Question by
ghostravenstorm · Mar 28, 2016 at 03:18 PM ·
texture2dimagerendertexture
How to convert from RenderTexture to Texture2D to EncodeToPNG?
I have an orthographic camera in scene rendering a minimap, but its causing a huge overhead in resources so I want to get rid of it while keeping the texture it renders. I only need a static image of what the camera renders and I can't find a way to export it to a PNG.
ReadPixels only seems to grab whatever is in the main frame buffer at the moment so that doesn't work for me. How do I call something like that but the input is from a specific camera or texture rather?
The RenderTexture class seems to be seriously lacking methods as compared to the Texture2D class.
public static void saveTexture(RenderTexture rt){
Texture2D image = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
// Some line of code that reads from 'rt' into 'image'
image.Apply();
byte[] bytes = image.EncodeToPNG();
Object.Destroy(image);
File.WriteAllBytes(Application.dataPath + "/../SavedScreen.png", bytes);
}
Comment