[iOS] How to grab screen and draw it as an image?

I googled for an hour in order to find out how to do it but couldn’t figure out still.

There seemed to be 2 ways for doing this thing.

one is using grabScreen from ofImage. I tried this one but I couldn’t draw a grabbed screen.

    myImage.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);
    myImage.grabScreen(0, 0, ofGetWidth(), ofGetHeight());

And the other is using ofxiOSScreenGrab. But I could not figure out how to use this.

These are the closest threads I found from the past.


Any suggestion how to do this on iOS?
I’m using OF 0.9.0 nightly builds by the way.

I think grabScreen or ofxiOSScreenGrab are used to save a screengrabs as a jpg /png image.
if you want to copy what’s being drawn on screen to an ofImage you could use ofFbo http://openframeworks.cc/documentation/gl/ofFbo.html .
you have to put everything you want to screen grab between fbo.begin(); fbo.end();
then you can copy the fbo pixels to an ofImage using fbo.readToPixels(image.getPixelsRef());

1 Like

Thank you very much!