I am trying to get an image out of a view where a user can paint on, or add some other views. With the iPad1 & 2 everything is working fine so far. But on the iPad3 it runs like a dog. I am just using the layers renderInContext method.
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)])
UIGraphicsBeginImageContextWithOptions(self.viewDrawableViewContainer.frame.size, NO, [UIScreen mainScreen].scale);
else
UIGraphicsBeginImageContext(self.viewDrawableViewContainer.frame.size);
[self.viewDrawableViewContainer.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
I know this is probably caused by the cpu which is equal to the ipad2 one, but it takes about 1 second. The more the user paints or adds, the longer it will take to render. Sometimes up to 5 seconds which is really inacceptable. So are there any options to improve performance? Any chance to maybe set a smaller rendering quality - I don't need a rendering in the highest retina resolution...
I would appreciate any help! Thanks in advance
You can also increase rendering speed by modifying the interpolation quality in your context before you call render in context. I was able to get much higher speed screenshot-ting with this change than by changing the scale factor.
Of course you can use both and you don't have to set the quality to None, Low still was an improvement for me.
CGContextSetInterpolationQuality(ctx, kCGInterpolationNone);
Also, for the scale factor as mentioned in the previous answer make sure your new scale factor is a multiple of the original i.e. if the screen scale is 1.0 you should do something like .5 and not .8. Using .8 will cause the render to have calculate more information (because it isn't an even scale) and thus make it slower than using 1.0 because.
Of course this won't be a good solution for everyone.
You can increase speed by rendering at lower resolution. Use a UIGraphicsBeginImageContextWithOptions scale factor less than 1.0, e.g. 0.5.
Also, if you don't need alpha you might get a small speed boost by passing YES for the opaque flag. I haven't timed the difference myself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With