x


How to take a Screenshot that includes GUI

I am trying to take a screenshot (with GUI controls shown on screen) whilst in web player and put the screenshot as a Texture2D

I know that Application.CaptureScreenshot("Screenshot.png") does not work from inside the web player

and Texture2D.ReadPixels() doesn't render any GUI controls.

Does anyone have any idea how to do this?

more ▼

asked Oct 21 '10 at 08:37 PM

Hugh gravatar image

Hugh
38 1 1 6

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Taken from an example from the docs: http://unity3d.com/support/documentation/ScriptReference/WWWForm.html

function UploadPNG() {
    // We should only read the screen after all rendering is complete
    yield WaitForEndOfFrame();

    // Create a texture the size of the screen, RGB24 format
    var width = Screen.width;
    var height = Screen.height;
    var tex = new Texture2D( width, height, TextureFormat.RGB24, false );
    // Read screen contents into the texture
    tex.ReadPixels( Rect(0, 0, width, height), 0, 0 );
    tex.Apply();

    // Encode texture into PNG
    var bytes = tex.EncodeToPNG();
    Destroy( tex );
}
more ▼

answered Nov 26 '10 at 11:49 PM

chief1234 gravatar image

chief1234
368 13 14 26

texture2D.ReadPixels() does not work. please read my question before answering it

Feb 22 '11 at 03:29 PM Hugh

The secret here is the yield WaitForEndOfFrame; This will allow the GUI to be rendered first, allowing ReadPixels() to catch the gui

Feb 22 '11 at 06:54 PM chief1234

Thank you, it works perfectly :)

Mar 02 '11 at 11:10 AM Hugh
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3811
x3125
x831
x106

asked: Oct 21 '10 at 08:37 PM

Seen: 2400 times

Last Updated: Oct 21 '10 at 08:37 PM