|
Read screen pixels into the saved texture data.
This will copy a rectangular pixel area from the currently active RenderTexture or the view (specified by /source/) into the position defined by destX and destY. Both coordinates use pixel space - (0,0) is lower left.
If recalculateMipMaps is set to true, the mip maps of the texture will also be updated. If recalculateMipMaps is set to false, you must call Apply to recalculate them.
This function works only on ARGB32 and RGB24 texture formats. The texture also has to have Is Readable flag set in the import settings.
On mobiles, if you read pixels from screen, the call will be deferred to the end of the frame. If you read pixels from the screen and call Apply right after it - apply will be deferred too. If you want to read from the screen and do something with the result you need to use coroutine.
var tex:Texture2D = null;
function Start()
{
StartCoroutine(rdp());
}
function rdp()
{
tex = new Texture2D(Screen.width,Screen.height,TextureFormat.RGB24,false);
tex.ReadPixels(Rect(0,0,Screen.width,Screen.height),0,0,false);
yield;
tex.SetPixel (0, 0, Color.white);
tex.Apply();
}
using UnityEngine;
using System.Collections;
public class example : MonoBehaviour {
public Texture2D tex = null;
void Start() {
StartCoroutine(rdp());
}
IEnumerator rdp() {
tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, false);
yield return null;
tex.SetPixel(0, 0, Color.white);
tex.Apply();
}
}
import UnityEngine
import System.Collections
class example(MonoBehaviour):
public tex as Texture2D = null
def Start():
StartCoroutine(rdp())
def rdp() as IEnumerator:
tex = Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false)
tex.ReadPixels(Rect(0, 0, Screen.width, Screen.height), 0, 0, false)
yield
tex.SetPixel(0, 0, Color.white)
tex.Apply()