那个简单的截图方式我这里用的老出错,不清楚什么原因,等什么时候找到原因了我重新改这篇文章
Rect t=new Rect(new Vector2(1,1),new Vector2(100,100));
public Texture2D i;
void Update(){
if (Input.GetMouseButtonDown(0)) {
Texture2D y= CaptureScreenshot2(t);
i = y;
}
}
Texture2D CaptureScreenshot2(Rectrect)
{
Texture2D screenShot=new Texture2D((int)rect.width,(int)rect.height,TextureFormat.RGB24,false);
//读取屏幕像素
screenShot.ReadPixels(rect,0,0);
screenShot.Apply();
//纹理数据组成一个png图片
byte[] bytes=screenShot.EncodeToPNG();
string filename=Application.dataPath+"/Screenshot.png";
System.IO.File.WriteAllBytes(filename,bytes);
return screenShot;
}