Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code example for iPhone UIGetScreenImage

Tags:

iphone

I've seen a number of posts on UIGetScreenImage, however, not a complete working (short) code example.

If anyone has a code example, from the prototype definition to an actual call, that would be greatly appreciated.

like image 601
John Muchow Avatar asked Dec 12 '22 23:12

John Muchow


2 Answers

CGImageRef UIGetScreenImage(void);

....

    CGImageRef screen = UIGetScreenImage();
    UIImage* screenImage = [UIImage imageWithCGImage:screen];
    CGImageRelease(screen); // you need to call this. 
                           // UIGetScreenImage violates the CF memory management rules.
    // Use screenImage as you like.
like image 132
kennytm Avatar answered Dec 31 '22 08:12

kennytm


Recently I needed to integrate taking screenshots into my iOS app. This question comes up pretty high in the search list on StackOverflow. However, since the initial public release of this method, Apple has made UIGetScreenImage private and any call to it will get your app rejected.

Apple made this post on their official forum regarding replacing calls to UIGetScreenImage.

Programmatic screenshots are no longer as simple as they use to be and there are now different ways to take a screenshot depending on the type of image that needs to be acquired.

The above Apple forum post explains how to take an image in each context.

like image 23
RLH Avatar answered Dec 31 '22 09:12

RLH