0

I'm trying to capture the screen inside of my app, it used to work just great, but now I only get a blurry image. like that:

blurry screen capture

This is my code:

- (UIImage *)takeScreenShotWithFrame:(CGRect)frame
{
    if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) {
        UIGraphicsBeginImageContextWithOptions(frame.size, NO, [UIScreen mainScreen].scale);
    } else {
        UIGraphicsBeginImageContext(frame.size);
    }
    [self.view drawViewHierarchyInRect:frame afterScreenUpdates:NO];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

What am I doing wrong?

Thanks in advance!

ytpm
  • 4,962
  • 6
  • 56
  • 113

1 Answers1

2

instead of:

[self.view drawViewHierarchyInRect:frame afterScreenUpdates:NO];

Try:

CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];
Murillo
  • 1,043
  • 8
  • 9