当前位置: 代码迷 >> 综合 >> Unity 截图
  详细解决方案

Unity 截图

热度:40   发布时间:2024-03-08 09:25:51.0
    /// <summary>/// 截图/// </summary>/// <param name="rect"></param>/// <returns></returns>IEnumerator  CaptureScreenshot2(Rect rect){yield return new WaitForEndOfFrame();// 先创建一个的空纹理,大小可根据实现需要来设置  Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);// 读取屏幕像素信息并存储为纹理数据,  screenShot.ReadPixels(rect, 0, 0);screenShot.Apply();// 然后将这些纹理数据,成一个png图片文件  byte[] bytes = screenShot.EncodeToPNG();string filename = Application.streamingAssetsPath + "/1.jpg";System.IO.File.WriteAllBytes(filename, bytes);Debug.Log(string.Format("截屏了一张图片: {0}", filename));}