Hi folks,
I've recently created a plug-in to allow the device screen (or a portion of it) to be saved to a file or the Saved Photos album. It's IOS only at the moment, I'm afraid (because that's my current focus) but will hopefully be of some use to others. It might also be helpful as further guidance to show how one can create a Gideros plug-in using Objective-C.
http://www.bowerhaus.eu/blog/files/gideros_snapshot.htmlThe obvious use of this code is to save user creations to the photo library but there might be other uses such as a simple form of "render to texture" while we're waiting for that to make it in the Gideros API.
As usual the code is MIT licensed so use it in your private or commercial projects as you like.
Best regards
Comments
It will leak memory. Just check the [[SnapshotHelper alloc] init]; position in the if() then else() block. Put [[SnapshotHelper alloc] init]; in the "if () then ...." block fixes it.
Application:getSnapshot(top,left,bottom,right) which returns binary data (say in PNG24 or jpeg format) that could be saved to a file?
I know this could be easily done for iOS applications using a code samples from the web...
I also know that OpenGL has an API for that already - to get the frame buffer or part of it as a memory array and then some extra code written in C is needed to convert the data to jpeg or png (I think such code is also available - like simplified version of libpng...).
This could be really useful.
http://www.khronos.org/opengles/documentation/opengles1_0/html/glReadPixels.html
http://giderosmobile.com/forum/discussion/1978
I've tried the BhSnapshotDemo, which seems to work, but the image doesn't show after it's (it seems to be transparent). Everything checks out when I print out properties of the image.
The plan is to use it to take a screenshot to use with the Twitter plugin for iOS.
Any ideas here?
Cheers,
Niclas
http://docs.giderosmobile.com/reference/gideros/RenderTarget
But with BHSnapshot what you are missing, is probably this one:
http://giderosmobile.com/forum/discussion/2508/problem-with-eaglview-m-keagldrawablepropertyretainedbacking-property-and-bhsnapshot-mm-in-ios6/p1
Anyway, you'e right, if you make that change to the kEAGLDrawablePropertyRetainedBacking property in the EAGLView.m file then the BhSnapshot works well. I'm using it for that exact purpose (submitting screenshots to Twitter and Facebook) in my Word Association Football game (www.wafga.me). The only real disadvantages are:
1) You have to compose a full screen view (that the user sees) in order to be able to snapshot it.
2) It's iOS only.
Best regards
Yes, after having completed the render target approach I realised that a) of course it won't work because the end result is not a file and b) it was too late. So I gave up on it.
Very pleased, now, to see there is a way around it in he BhSnapshot plugin! Thanks very much for pointing me in the right direction. Will try soon again. Sharing screenshots would fit my game very neatly indeed.
Bowerandy, I don't quite get disadvantage #1. Do you mean you have to show the screenshot to the player as it's snapped? And it has to be full-screen? Neither are deal breakers for me, but would like to have the limitations clear in my mind as I go back in with renewed gusto.
Niclas
http://giderosmobile.com/labs/media
Fragmenter - animated loop machine and IKONOMIKON - the memory game
In another case, Spin Off! (http://spinoffgame.com) I use this to be able to take a snapshot of a race track that the user has just drawn so I can reduce it in size and use it as a thumbnail to identify the track later. This means that, for a few seconds, while the track is saved I have to blow it up to full screen. It's a bit of a pain but doesn't really look that noticeable within the gameplay.
Best regards
Kezsegh, thanks for the Media pointer. Would the Gideros Media plugin work to send a screenahot to Twitter, or would it suffer from the same Apple change? Has anyone got recent experiences with Media? I noticed it also has an Android plug, so worth considering because of that.
Niclas
Fragmenter - animated loop machine and IKONOMIKON - the memory game