IPad 3 renderInContext slow - Poor rendering performance

I am trying to get an image from a view where the user can draw, or add some other views. With iPad1 and 2, everything still works. But on iPad3 it works like a dog. I just use the 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 that this is probably caused by a processor equal to ipad2, but it takes about 1 second. The more the user draws or adds, the longer it will take to render. Sometimes up to 5 seconds, which is really unacceptable. So are there any options for improving performance? Any chance, perhaps, to set lower quality of rendering - I don't need rendering in the highest resolution of the retina ...

I would be grateful for any help! thanks in advance

+6
ios iphone ipad ipad-3
Jul 11 2018-12-12T00:
source share
2 answers

You can increase the speed by rendering at a lower resolution. Use a scale factor of UIGraphicsBeginImageContextWithOptions less than 1.0, for example. 0.5.

Also, if you don't need alpha, you can get a slight speed boost by passing YES for an opaque flag. I myself have not dated this difference.

+9
Aug 18 2018-12-18T00:
source share

You can also increase the rendering speed by changing the quality of the interpolation in your context before you invoke the rendering in the context. I was able to get a much faster screenshot speed with this change than by changing the scale factor.

Of course, you can use both options, and you do not need to set the quality to None, Low was still an improvement for me.

 CGContextSetInterpolationQuality(ctx, kCGInterpolationNone); 

Also, for the scaling factor, as indicated in the previous answer, make sure your new scaling factor is a multiple of the original, i.e. if the screen scale is 1.0, you should do something like .5, not .8. Using .8 will cause the render to compute more information (because it is not an even scale) and thus makes it slower than using 1.0 because.

Of course, this will not be a good solution for everyone.

+16
May 9 '13 at 2:39
source share



All Articles