iPad 3 renderInContext slow - Bad rendering performance

孤人 提交于 2019-12-04 12:01:40

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/11435210/ipad-3-renderincontext-slow-bad-rendering-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!