Unity 截屏
Posted clhxxlcj
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity 截屏相关的知识,希望对你有一定的参考价值。
//截屏 public void CaptureScreen2(Camera c, Rect r) //捕抓摄像机图像并转换成字符数组 RenderTexture rt = new RenderTexture((int)r.width, (int)r.height, 0); //targetTexture目标纹理 c.targetTexture = rt; //Render手动渲染相机 c.Render(); //active目前活跃的渲染纹理 RenderTexture.active = rt; Texture2D screenShot = new Texture2D((int)r.width, (int)r.height, TextureFormat.RGB24, false); //读取像素 screenShot.ReadPixels(r, 0, 0); screenShot.Apply(); //摄像机目标渲染纹理 c.targetTexture = null; RenderTexture.active = null; GameObject.Destroy(rt); //将此纹理编码为PNG格式。 byte[] bytes = screenShot.EncodeToPNG(); string filename = @"d:\photo-whzq\Screenshot.png"; System.IO.File.WriteAllBytes(filename, bytes); PlayerPrefs.SetString(IMAGEFILE, filename);
以上是关于Unity 截屏的主要内容,如果未能解决你的问题,请参考以下文章
Unity报错:Read only asset Packages/com.xxxxx.xxx.xxxx/Editor/VSCodeDiscovery.cs.IPGSD has no meta(代码片段