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)
最新推荐文章于 2024-11-02 14:12:37 发布
该代码展示了如何在Unity游戏引擎中创建一个RenderTexture,将其设置为主相机的目标纹理,渲染当前画面,然后读取并存储为Texture2D对象,用于获取1080p的屏幕截图。
摘要由CSDN通过智能技术生成