Is it possible to save RenderTextures into png files for later use?

Hi,

Is it possible to save RenderTextures into png files for later use?

Use ReadPixels to read the RenderTexture into a Texture2D and save that using EncodeToPNG.

Interesting question.

You can grab contents of the current render target with Texture2D.ReadPixels

Texture2Ds can generate png data with Texture2D.EncodeToPNG.

public RenderTexture rt;
// Use this for initialization
public void SaveTexture () {
byte bytes = toTexture2D(rt).EncodeToPNG();
System.IO.File.WriteAllBytes(“C:/Users/egsha/SavedScreen.png”, bytes);
}
Texture2D toTexture2D(RenderTexture rTex)
{
Texture2D tex = new Texture2D(1920, 1080, TextureFormat.RGB24, false);
RenderTexture.active = rTex;
tex.ReadPixels(new Rect(0, 0, rTex.width, rTex.height), 0, 0);
tex.Apply();
return tex;
}