UnityEngine.Texture2D.ReadPixels C# (CSharp) Method

ReadPixels() public method

Read pixels from screen into the saved texture data.

public ReadPixels ( Rect source, int destX, int destY, [ recalculateMipMaps ) : void
source Rect Rectangular region of the view to read from. Pixels are read from current render target.
destX int Horizontal pixel position in the texture to place the pixels that are read.
destY int Vertical pixel position in the texture to place the pixels that are read.
recalculateMipMaps [ Should the texture's mipmaps be recalculated after reading?
return void
        public void ReadPixels(Rect source, int destX, int destY, [DefaultValue("true")] bool recalculateMipMaps)
        {
            INTERNAL_CALL_ReadPixels(this, ref source, destX, destY, recalculateMipMaps);
        }

Same methods

Texture2D::ReadPixels ( Rect source, int destX, int destY ) : void

Usage Example

コード例 #1
1
ファイル: ThumbGen.cs プロジェクト: RaymondEllis/ViralCubers
	public override void OnInspectorGUI()
	{
		if (GUILayout.Button("Generate Thumb"))
		{
			Camera cam = (Camera)target;
			CameraClearFlags clearFlags = cam.clearFlags;
			cam.clearFlags = CameraClearFlags.Depth;

			RenderTexture renTex = new RenderTexture(size, size, 1);
			cam.targetTexture = renTex;
			cam.Render();
			cam.targetTexture = null;

			Texture2D tex = new Texture2D(size, size);

			RenderTexture.active = renTex;
			tex.ReadPixels(new Rect(0, 0, size, size), 0, 0);
			RenderTexture.active = null;

			byte[] data = tex.EncodeToPNG();

			string scenePath = Path.GetFullPath(Path.GetDirectoryName(EditorSceneManager.GetActiveScene().path));
			string sceneName = EditorSceneManager.GetActiveScene().name;
			string file = scenePath + "/Thumbnails/" + sceneName + ".png";
			File.WriteAllBytes(file, data);
			Debug.Log("Thumbnail saved to: " + file);

			cam.clearFlags = clearFlags;
		}

		base.OnInspectorGUI();
	}
All Usage Examples Of UnityEngine.Texture2D::ReadPixels