Make UIImage from UIView, but NOT in the main topic

I use the well-known template to create a UIImage from a 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 subqueries on it, so this conversion process takes about 3 + (!!!) seconds.

I tried using it in another thread that runs in the background, and it really improved performance.

The only problem is that, as I can remember, it is not allowed to create things related to the user interface out of the main thread.

Am I mistaken and is this beautiful? Or - if I'm right - what can be done to increase productivity? is there any other method that i can use in another thread but doing the same job?

Thanks a lot!

+4
source share
1 answer

In the end, I just did it in a different thread, and everything works fine.

0
source

Source: https://habr.com/ru/post/903941/


All Articles