iphoneiosipadipad-3

iPad 3 renderInContext slow - Bad rendering performance


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


Solution

  • 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.