言語: 日本語
  • C#
  • JS
  • Boo

スクリプト言語

お好みのスクリプト言語を選択すると、サンプルコードがその言語で表示されます。

Texture2D.ReadPixels

public function ReadPixels(source: Rect, destX: int, destY: int, recalculateMipMaps: bool = true): void;

Parameters

source 読み込み元のビューの長方形領域。
destX テクスチャ内の読みこむピクセルの水平位置。
destY テクスチャ内の読みこむピクセルの垂直位置。
recalculateMipMaps テクスチャのミップマップを読んだ後に再計算するか?

Description

スクリーン画面のピクセルデータを読み込みます

現在アクティブなRenderTextureまたは定義位置のビューに(/ソース/パラメータで指定された)から長方形ピクセル領域にコピーします 左下を(0,0)座標とするピクセル空間を使用します。 recalculateMipMapsがTrueに設定されている場合、テクスチャのミップマップは更新されます。 recalculateMipMapsがFalseに設定されている場合は、Applyをコールし再計算する必要があります。 この機能はARGB32やRGB24へテクスチャフォーマットでのみ動作します。 テクスチャはまたRead/Writeフラグをインポート設定で設定します 読み込むピクセルはフラッシュをサポートしていません。

	// This script should be attached to a camera. 

	// Grab the camera's view when this variable is true.
	var grab: boolean;

	// The "display" is the object whose texture will be set
	// to the captured image.
	var display: Renderer;


	function OnPostRender() {
		if (grab) {
			// Make a new texture of the right size and
			// read the camera image into it.
			var tex = new Texture2D(128, 128);
			tex.ReadPixels(new Rect(0, 0, 128, 128), 0, 0);
			tex.Apply();
			
			// Set the display texture to the newly captured image.
			display.material.mainTexture = tex;
			
			// Reset the grab variable to avoid making multiple
			// captures.
			grab = false;
		}
	}

See Also: EncodeToPNG.