JPGEncoder.cs Unity3D压缩截图

时间:2020-12-13 06:17:55
【文件属性】:
文件名称:JPGEncoder.cs Unity3D压缩截图
文件大小:5KB
文件格式:ZIP
更新时间:2020-12-13 06:17:55
JPGEncoder 我在网上找到了JPGEncoder.cs纯代码压缩类 添加函数 IEnumerator CaptureScreenshotJPG(Rect rect) { yield return new WaitForEndOfFrame (); // 先创建一个的空纹理,大小可根据实现需要来设置 TextureFormat aTextureFormat; ; aTextureFormat = TextureFormat.RGB24; Texture2D screenShot = new Texture2D ((int)(rect.width), (int)(rect.height), aTextureFormat, false); // 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels (rect, 0, 0); screenShot.Apply (); JPGEncoder encoder = new JPGEncoder (screenShot, 20);//质量1~100 encoder.doEncoding (); while (!encoder.isDone) yield return null; string filename = Application.persistentDataPath + "/" + "screenName.png"; System.IO.File.WriteAllBytes (filename, encoder.GetBytes ()); Debug.Log (string.Format ("截屏了一张图片: {0}", filename)); }
【文件预览】:
JPGEncoder.cs

网友评论

  • 用不了,unity2018试的。截出来的图都是绿的