- Home /
Is it possible to create a texture from a static image from a camera without using CaptureScreenshot or RenderToCubemap
I'd like to create a thumbnail of the user's customized character just to have a static image within the game (eg, I don't need or want to write to disk and it doesn't need to be rendered live). The Camera class doesn't have any obvious way of getting the pixels from a camera, nor do RenderTextures. Currently, I'm using Camera.RenderToCubemap, extracting the pixels from the desired face, and copying them to a texture, but this process is tedious, difficult to set up, and frankly seems unnecessary. Is there a better way of getting the pixels from a camera for use in a Texture2D?
ETA: Using Mike's solution, I used the following to get the image I wanted (C#, requires RenderTextures):
Texture2D newTexture = new Texture2D (thumbnailCamera.targetTexture.width, thumbnailCamera.targetTexture.height, TextureFormat.RGB24, false);
GameObject.DontDestroyOnLoad (newTexture);
RenderTexture.active = thumbnailCamera.targetTexture;
newTexture.ReadPixels (thumbnailCamera.pixelRect, 0, 0);
newTexture.Apply ();
Answer by Mike 3 · May 25, 2010 at 06:16 PM
You can use Texture2D.ReadPixels: http://unity3d.com/support/documentation/ScriptReference/Texture2D.ReadPixels.html
It'll grab the whole screen, not just the camera you want, but you could force it to dsplay only the wanted camera temporarily