- Home /
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?
Answer by chief1234 · Nov 26, 2010 at 11:49 PM
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 );
}
texture2D.ReadPixels() does not work. please read my question before answering it
The secret here is the yield WaitForEndOfFrame; This will allow the GUI to be rendered first, allowing ReadPixels() to catch the gui