Using RenderTexture, Texture2D and a camera to get a PNG. The other posts on the forum didn’t tie everything together, so after figuring it out, I thought i’d “give back.”
Anyway.
You have a camera, that camera’s target texture is set to a RenderTexture, and a texture2d. then you
thumbCam.Render();
RenderTexture.active = thumbnail; //thumbnail is a RenderTexture
thumb_tex = new Texture2D(256, 256);
thumb_tex.ReadPixels(thumbCam.pixelRect,0,0);
RenderTexture.active = null;
thumb_tex.Apply();
var png : byte[ ] = thumb_tex.EncodeToPNG();
Hope this helps… maybe it is something that could be cleaned up and added to the RenderTexture documentation?
First, I want to thank aaron for the post. This was very helpful putting the pieces together for me. I have to admit the description of the RenderTexture.active property totally threw me off.
However, now that I have this working, I’m seeing a very odd bug. My code largely follows aaron’s example, but for some reason on Windows the texture generated from the RenderTexture/Camera is vertically inverted (ie the entire texture is upside down). Doesn’t seem to matter what browser I view the project in. On OS X in Firefox, it looked fine