unity获取RenderTexture内容并保存的方法

     private void Save()
     {
         var eye = eyes[0];
         RenderTexture.active = (RenderTexture)eye.TexturePtr;
 
         Texture2D png = new Texture2D(RenderTexture.active.width, RenderTexture.active.height, TextureFormat.ARGB32, true);
         png.ReadPixels(new Rect(0, 0, RenderTexture.active.width, RenderTexture.active.height), 0, 0);
 
         byte[] bytes = png.EncodeToPNG();
         string path = string.Format(@"/sdcard/dump/{0}{1}.png",eye.Side,frameCount);
 
         FileStream file = File.Open(path, FileMode.Create);
         BinaryWriter writer = new BinaryWriter(file);
         writer.Write(bytes);
         file.Close();
         writer.Close();
 
         Destroy(png);
         png = null;
 
         Debug.Log("Save Down");
     }

你可能感兴趣的:(unity获取RenderTexture内容并保存的方法)