Unity截屏并显示在Image上
Texture2D screenShot;
public Image image;
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
StartCoroutine(ScrrenCapture(new Rect(0, 0, Screen.width, Screen.height)));
}
}
IEnumerator ScrrenCapture(Rect rect)
{
screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
yield return new WaitForEndOfFrame();
screenShot.ReadPixels(rect, 0, 0);
screenShot.Apply();
Sprite sp = Sprite.Create(screenShot, new Rect(0, 0, screenShot.width, screenShot.height), new Vector2(0.5f, 0.5f), 100.0f);
image.sprite = sp;
}