iPad 3 slow screenshot

Go To StackoverFlow.com

9

In my app I'm using a screenshot method. On my iPad 2 it's very fast (about 130 ms) to execute this method. But on the new iPad (certainly due to the highest resolution and the same CPU) it's taking like 700 ms ! Is there a way to optimize my method ? Perhaps there's a way to work directly with graphic card ?

Here's my screenshot method :

- (UIImage *)image {
CGSize imageSize = self.bounds.size;

if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);
else UIGraphicsBeginImageContext(imageSize);

CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSaveGState(context);
CGContextTranslateCTM(context, [self center].x, [self center].y);
CGContextConcatCTM(context, [self transform]);
CGContextTranslateCTM(context, -[self bounds].size.width * [[self layer] anchorPoint].x, -[self bounds].size.height * [[self layer] anchorPoint].y);
[[self layer] renderInContext:context];
CGContextRestoreGState(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;

}

Thanks for your help.

2012-04-04 07:13
by Pierre
Can't help you here. But I think that 700ms is really slow. Shouldn't it be like 130ms * 4 = 520ms - Christian Schnorr 2012-04-04 07:24
Try using UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0.0f); instead of UIGraphicsBeginImageContextWithOptions(imageSize, NO, [UIScreen mainScreen].scale);. This will make for 1:1 screenshot. Or is there a specific reason you need [UIScreen mainScreen].scale there - Rok Jarc 2012-04-04 07:26
@Jenox yeah it depends but it's more like 700ms - Pierre 2012-04-04 07:45
@Rokjarc Thank you. It's still slow : - Pierre 2012-04-04 07:46
Unfortunately, I think that it isnt going to be 520ms. Lets remember that between the iPad 2 and 3 they quadrupled the pixels, but only doubled the graphics horspower and left the CPU the same. I think it is perhaps feasible that 700 ms might actually be the best you may get for a screenshot of full resolutio - trumpetlicks 2012-06-04 22:17
@trumpetlicks yes. So now I'm taking screenshots with un retina resolution and then I'm stretching them to retina resolution - Pierre 2012-06-05 07:22
well then in this case I would FULLY expect more than 520ms. For a simple screenshot thats one thing, but when you are actually having to process a smaller image and mathematically generate for the more pixels, thats very processing heavy!! - trumpetlicks 2012-06-05 12:04
@Pierre I found the same issue and opted for the same solution: taking the screenshot at half the resolution for the new iPad. In that way I get reasonable speed and, due to the nature of the animation I do with the screenshot, the loss in quality is almost non-noticeable. Just to mention that I don't find this problem with the iPhone 4 or 4S, they take retina screenshots just fine - flainez 2012-06-19 07:45
This piece of code actually works, but it doesn't take into account device orientation - Juan Carlos Ospina Gonzalez 2014-07-10 16:19
The resource at this link helped me find the way to compensate for device orienation http://i-gorod.org/itblog/2013/02/28/ios-screen-capture-depending-on-device-orientation - Juan Carlos Ospina Gonzalez 2014-07-11 07:36


3

I think it was the developer of Flipboard talking about this issue on a podcast. It is a real issue with the iPad 3, because they've quadrupled the pixels.

What he was doing was taking the screenshot ahead of time in the background, not when the user initiated the action - in his case when the user "flipped" the page.

I don't know whether this will help you in your case, but it is certainly a viable approach for many cases.

2012-06-08 02:21
by Nick Pestov


0

This may or may not be sufficient for your application but one option is to scale the screenshot down, e.g. pass 0.5 as your scale factor to UIGraphicsBeginImageContextWithOptions. 4x faster but the tradeoff is a loss of detail/resolution.

2012-08-18 22:50
by darrinm
Ads