public Texture2D PrintScreen()
{
int width = 1920;
int height = 1080;
RenderTexture rt = new RenderTexture(width, height, 0);//渲染一张1920*1080的图
Camera.main.targetTexture = rt;//传到主摄像机上
Camera.main.Render();//渲染
RenderTexture.active = rt;
//Texture2D screenShot = new Texture2D(width, height, TextureFormat.RGB24, false);
Texture2D screenShot = new Texture2D(width, height, TextureFormat.RGB24, false);
screenShot.ReadPixels(new Rect(0, 0, width, height), 0, 0);//读像素
screenShot.Apply();
Camera.main.targetTexture = null;
RenderTexture.active = null;
Destroy(rt);
return screenShot;
}
unity-截取屏幕(不包含canvas)
最新推荐文章于 2025-02-18 14:29:38 发布
