- Home /
Is is possible to output screenshots from Unity?
I'm creating a car configurator and after the user has customized their car, I'd like to output a jpg screencap and submit it to the server. Is this even possible?
Answer by Ehren · Nov 16, 2009 at 09:52 PM
Yes, it's possible to output screenshots.
The following doc page contains an example of uploading a png of the current frame to a server.
http://unity3d.com/support/documentation/ScriptReference/WWWForm.html
I haven't tried it, but hopefully the code still works in 2.6.
EDIT: From the Blurst Technology blog: JPEG Encoding in Native Unity JavaScript.
Answer by Bampf · Nov 16, 2009 at 09:56 PM
Yes, it is possible. I haven't done this myself, but in theory you could approach it the following way, if you have Unity Pro.
- Set up a RenderTexture, and tell a camera in your scene to render to it.
Documentation: http://unity3d.com/support/documentation/Components/class-RenderTexture.html
- Of course, sending raw pixels for a large image might be prohibitive. If this is a problem you might be able to use the Texture2D class's EncodeToPNG method for compressing the image to PNG format. There is some sample code in the Unity documentation that even shows how to save it to a file.
[sorry - I'm a new user, can only post one hyperlink. Just search the Unity script reference documentation for Texture2D.EncodeToPNG.]
A small complication: RenderTexture and Texture2D are both subclasses of Texture, but offhand I do not see support for directly copying from one to the other. So you may need to do a GetPixels from the RenderTexture, then SetPixels to a new Texture2D object. Then you can use Texture2D's EncodeToPNG method as planned.
Hope this helps.
I see Ehren posted an answer just as I did, and his answer seems closer to what you were asking for. $$anonymous$$y answer might have value in two situations however, so I think I will leave my answer up for posterity. 1) If the image being rendered isn't the full screenshot but ins$$anonymous$$d some other view, you would want to render from a camera. 2) If you wanted to save to a file locally rather than send it to a server. For example if you wanted to generate a thumbnail image for a saved game.
Answer by duck · Nov 16, 2009 at 10:06 PM
It sounds like your project is probably a webplayer build, but in case it's not, you should probably also check out: Application.CaptureScreenshot
Of course you'll still need the WWWForm class to upload the file it creates.
Answer by Ricardo · Nov 30, 2009 at 05:37 PM
A couple days ago there was a post on the Blurst technology blog about encoding JPEGs from UnityScript, which they use on Splume to upload to their server level editor thumbnails. Their post is informative and might be able to help you.
Answer by William Grand · Apr 23, 2010 at 08:26 PM
Any idea how to send a screenshot to the printer?
Adding a question as an answer to a question probably won't give you an answer. Anyways: I don't think this is even possible without using plugins. You might get it working in standalones, though ...
Your answer
Follow this Question
Related Questions
How to Render to Fullscreen Texture pixel perfect 2 Answers
ReadPixels() vs Windows ScreenShot 0 Answers
Screen explodes into colors bug, "screen position outside of view frustum" 0 Answers
2D graphic problem with tilemap and resolution 0 Answers
How to check if a Renderer has instantiated materials without instantiating them? 1 Answer