-2

I obtained this code from the apple documentation...

+ (UIImage *)screenshot {
    CGSize imageSize = [[UIScreen mainScreen] bounds].size;
    if (NULL != UIGraphicsBeginImageContextWithOptions) {
        UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
    } else {
        UIGraphicsBeginImageContext(imageSize);
    }

    CGContextRef context = UIGraphicsGetCurrentContext();

    for (UIWindow *window in [[UIApplication sharedApplication] windows]) {
        if (![window respondsToSelector:@selector(screen)] || [window screen] == [UIScreen mainScreen]) {

            CGContextSaveGState(context);

            CGContextTranslateCTM(context, [window center].x, [window center].y);

            CGContextConcatCTM(context, [window transform]);

            CGContextTranslateCTM(context,
                                  -[window bounds].size.width * [[window layer] anchorPoint].x,
                                  -[window bounds].size.height * [[window layer] anchorPoint].y);


            [[window layer] renderInContext:context];


            CGContextRestoreGState(context);
        }
    }


    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();
    return image;
}

However, I have one small issue with it. I want to include the status bar in my screenshot. How do I do this? Or is there a better method to do this with?

-Henry

Dummy Code
  • 1,858
  • 4
  • 19
  • 38

1 Answers1

-1

Here is the way I ended up doing this...

+ (UIImage *)screenshot {

    CGImageRef screen = UIGetScreenImage();
    UIImage *image = [UIImage imageWithCGImage:screen];
    CGImageRelease(screen);

    return image;
}

Although it is not App Store approvable it is the best way to do it.

Dummy Code
  • 1,858
  • 4
  • 19
  • 38
  • 1
    That's amazing way, but is UIGetScreenImage a private api, so that the App Store doesn't allow it?And how can we use it to take a specified region screenshot? – Suge Aug 11 '13 at 06:42