Advertisement
Guest User

Untitled

a guest
Jan 19th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.59 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class SaveRenderTexture : MonoBehaviour {
  4.     public RenderTexture texture;
  5.  
  6.     [ContextMenu("Save")]
  7.     private void Save() {
  8.         var currentActiveRT = RenderTexture.active;
  9.         RenderTexture.active = texture;
  10.        
  11.         var screen = new Texture2D(this.texture.width, this.texture.height, TextureFormat.ARGB32, false);
  12.        
  13.         screen.ReadPixels(new Rect(0, 0, this.texture.width, this.texture.height), 0, 0);
  14.         var bytes = screen.EncodeToPNG();
  15.      
  16.         System.IO.File.WriteAllBytes(Application.dataPath + "/Temp/screen.png", bytes);
  17.        
  18.         RenderTexture.active = currentActiveRT;
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement