How to render a camera image to png

Hi, I’m trying (unsuccessfully so far) to take a camera image and get a RenderTexture from it. Once I have the RenderTexture, I need to use Texture2D.ReadPixels to read the RenderTexture, so that it can be saved out as a PNG file.

I have this code to get the initial RT from the camera…

`
RenderTexture c1render = new RenderTexture(80, 80, 24);

c1.targetTexture = c1render;

c1.Render();

c1.targetTexture = null;
`

and the following to save a Texture2D…

File.WriteAllBytes("mypath/somefile.png", texture2d.EncodeToPNG());

The bit I’m having trouble with is getting a Texture2D from the RenderTexture of my camera.

Any help would be gratefully received

Hi! there,

You can cast textures like this:

//The variables
var image:Texture;
var image2d:Texture2D;

//Convert the texture to a Texture2D
image2d = image as Texture2D;

Hope this helps,
Benproductions1