Application.CaptureScreenshot -> to an in game texture.

Hi,

For my architectural project, I’m working with 3 cameras:

  • a map cam (for the minimap)
  • a FPS cam (to walk into my building)
  • a rotate cam (to turn around my building)

I’ve got a GUI system displayed on the FPS cam and the rotate cam.

Right now, i can take screenshots by pressing the “C” key and they are saved on my computer as “Screenshot_00.png”,…

But I’d like to do a pictures album, in GUI. Everything set except, I can’t save my screenshots into my slots text1, text2,… of my script (and then display text1,…).

If i’m using a RTT, on my cameras I can see anything anymore.

So I’ve got 2 solutions:

  1. use the “Application.CaptureScreenshot” and send that screenshot into a texture → I don’t know how to do that.

  2. I think use 5 cameras(2 FPS + 2 Rotate + 1 mapcam)
    So everytime 1 normal cam one RTT cam.
    But I don’t think that’s really good to use 3 RTT cam at the same time for the performances.
    But how can I transfer a Live RTT to a single image ?
    Or how can I use the RTT only when I press the C Key and shut it down when it’s not pressed ?

It’s my major projet for the end of my scolarship(schoolship? I’m Belgian)I have 90 000 poly so I want to keep it fluid.

Thank’s a lot for your help

You can use Texture2D.ReadPixels to save the contents of the screen to a texture. You can also load a PNG file using the WWW class with a file: URL.

Ok,

I found this
http://answers.unity3d.com/questions/2486/convert-a-rendertexture-to-a-texture2d

How can I say that my read.pixels use the current view and not my RtT because some times i’ll have 2 RtT in the same time (one for the map, another for the screenshot). And I rather prefer use the current view than the rendertexture.
I will enable and “unenable” my camera, wich doing the RTT for the screenshot, in my if (screenshotbutton… to save some perfomances.

Here is my code:
I’ve first declared:
public RenderTexture Rtt;
private static Texture2D test;
private Texture test2;

GUI.Label(new Rect(Screen.width / 2, Screen.height / 2, 256,256), test2);


// -------------------------------------------- Screenshot Button --------------------------------------------


        if (GUI.Button(new Rect(ButtonsX+280, ButtonsY+Screen.height / 2, ButtonWH, ButtonWH), "", Screenshot))
        {
			
			test.ReadPixels(new Rect(0, 0, Rtt.width, Rtt.height), 0, 0);
			test.Apply();
	
			test2 = test;
			

        }

With this code it says :Object reference not set to an instance of an object (line 345 → test.ReadP…)

For the other way, for my presentation I’ll present my major project in another computer (in my school).
How can i be sure that the URL will stay good?

I just want to create my png in the Exe folder, and if it’s possible, load them from there.

Thank’s you for your help

A question, does this function work to grab from the screen into a texture on the free version of Unity?

@Boobi: did you actually instantiate a new Texture2D object before using it?

test = new Texture2D( Rtt.width, Rtt.height);

@imaginaryHuman: Yes, ReadPixels works in the free version of Unity.

I’m having trouble getting it to grab properly. I can see it might grab once but not every frame (it’s in a camera’s OnPostRender() function with a manual Render() call via Update() function). It seems to grab the screen initially into some kind of texture but thereafter does not seem to have grabbed it into the existing texture that my cube is textured with. I see the cube textured with an undisturbed texture on most sides except on one side it has the grabbed version. Doesn’t make any sense. Other times it grabs continually but from some strange camera angle.

See my example code in this other thread: http://forum.unity3d.com/viewtopic.php?t=55109