- Home /
I need to take a screenshot from a FLASH BUILD
Hi,
As stated in the title, I need to take a screenshot of my scene and afterwards send it to a server. I believe I can handle the uploading on my own using WWWForms, but I can't get the screenshot part to work. I just want to remind you I'm working on a Flash build; as far as I'm concerned, nor Application.CaptureScreenshot() nor Texture.ReadPixels() do work on this platform..
Thanks
O$$anonymous$$ so basically I have to create a handler in an AS3 clas that will make the screenshot and call it from a C# class. Thanks, it's a bit annoying but at least there's a way to do it! Just a small additionnal question, as I never used AS3 before starting this project: can I access these Stage3D/Context3D from any AS class (are they public static) or do I have to extend a particular one?
You should be able to access them from any class, like so:
var context:Context3D = UnityNative.stage.stage3Ds[0].context3D;
Yeah, it's annoying, and you're probably going to run into some headaches getting the pixel data back to C#, but it's definitely doable.
One thing you should be aware of: When you're messing with Context3D, it's probably best to do so from an OnPostRender handler in a $$anonymous$$onoBehaviour attached to a camera. The reason for this is that the Unity flash engine is setting and clearing all kinds of state flags and doing a whole lot of other stuff behind the scenes at various times, which can interfere with your own code, if you're accessing Context3D from an Update handler.
Thanks for the snippet and the tips. I'm already aware about the OnPostRender thing, I'm currently using a coroutine with a yield waitForEndOfFrame;
which should do the trick :)
As you're suggesting I'll get some headaches from passing my screenshot back to Unity, would you know by any chance if there is a simple way to upload it directly from AS3 to a server? Because to be fair that's the only reason I need to pass it back to C#, otherwise I don't even display it within my scene.
By the way: I assume your answer is the correct one (considerating the lack of info I managed to get on the internet), I'll just wait for this afternoon to implement it to mark it as such.
I don't have anything in store myself, but I'm sure other people have solved that problem... A quick Google search gives these two posts, for example: http://www.quietless.com/kitchen/upload-bitmapdata-snapshot-to-server-in-as3/ http://www.quietless.com/kitchen/dynamically-create-an-image-in-flash-and-save-it-to-the-desktop-or-server/
Perfect, managed to get everything up'n'running using the second link, modifying it a bit to use Context3Ds ins$$anonymous$$d of DisplayObjects and then linking everything through Unity in C# and AS.
Thanks for everything.
PS: would you "convert your comment to answer", so that I can accept it as the correct answer and thus give you credit?
Answer by Philipp · Mar 04, 2013 at 10:23 AM
Unfortunately, this isn't currently possible from within C# or JS. The only way you're going to get this to work is to dig into Flash's Stage3D API and use Context3D's drawToBitmapData to grab the backbuffer into an AS3 BitmapData.
Your answer
Follow this Question
Related Questions
Show Screenshot in display. 2 Answers
WebRequests have very slow transfer speed for large uploads 0 Answers
How implement my game on the website? 5 Answers
How to upload a web game to dropbox without errors? 2 Answers
Flash player vs. Unity Web player 0 Answers