通过读取屏幕缓存然后转化为Png图片进行截图,并可直接使用png图片作为缩略图。(截图存储路径你可以自己设置)
IEnumerator GetCapture()
{
yield return new WaitForEndOfFrame();
int width = Screen.width;
int height = Screen.height;
Texture2D tex = new Texture2D(width,height,TextureFormat.RGB24,false);
tex.ReadPixels(new Rect(0,0,width,height),0,0,true);
byte[] imagebytes = tex.EncodeToPNG();//转化为png图
tex.Compress(false);//对屏幕缓存进行压缩
imageGetcomponent《RawImage>().Texture = tex;//对屏幕缓存进行显示(缩略图)
File.WriteAllBytes(Application.dataPath + “/screencapture.png”,imagebytes);//存储png图
}
unity 截图
最新推荐文章于 2024-05-17 11:27:10 发布