Unity PC拍照(保存电脑本地)

xiaoxiao2021-02-28  100


public void paiZhao() //拍照 { StartCoroutine(UploadPNG()); } IEnumerator UploadPNG() { yield return new WaitForEndOfFrame(); int width = Screen.width; int height = Screen.height; // 创建一个屏幕大小的纹理,RGB24 位格(24位格没有透明通道,32位的有) Texture2D tex = new Texture2D(width, 1250, TextureFormat.RGB24, false); // 读取屏幕内容到我们自定义的纹理图片中 tex.ReadPixels(new Rect(0,315, width, 1250), 0, 0); // 保存前面对纹理的修改 tex.Apply(); // 编码纹理为PNG格式 byte[] bytes = tex.EncodeToPNG(); // 销毁吴永的图片纹理 Destroy(tex); File.WriteAllBytes(Application.streamingAssetsPath + "/onMobileSavedScreen.png", bytes); }

上面是一种拍照的方式,下面再介绍一种更加简单的截屏方式:



FR: 徐海涛(Hunk Xu)

转载请注明原文地址: https://www.6miu.com/read-63945.html

最新回复(0)