ytpm
ytpm

Reputation: 5160

iOS screen capture is blurry for some reason

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!

Upvotes: 0

Views: 2581

Answers (1)

Murillo
Murillo

Reputation: 1183

instead of:

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

Try:

CGContextRef context = UIGraphicsGetCurrentContext();
[self.view.layer renderInContext:context];

Upvotes: 2

Related Questions