开发者

Make UIImage From UIView but NOT in the main thread

I'm using the well-known pattern to create an UIImage from an UIView:

+ (UIImage *) imageWithView:(UIView *)view
{
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, [[UIScreen mainScreen] scale]);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage * img = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return img;
}

Now, my problem is that i have a very complex view with a lot of subviews on it, so this process of conversion takes about 3+(!!!) seconds.

I tried forking it into another thread that run in the background and it really did improve the performance.

The only problem is that as can I remember, it is not allowed to make UI related stuff not in the main thread.

Am I wrong and this is perfectly fine? Or - if i'm right - what can be done to improve performance? is there any other method that i can use in a d开发者_运维技巧ifferent thread but does the same work?

Thanks a lot!


In the end i just did it in another thread, and everything is working fine.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜