(iphone) How to create UIImage from imageRef which is created in a background stream?

UIImage * img = [UIImage imageWithCGImage: imageRef];
can only be done in main-thread .. bah ..

Now all my images create functions that must be executed in the background thread, must be changed.
The question is how to change the above line.

The usual steps for creating an image were as shown below.

CGImageRef imageRef = CGBitmapContextCreateImage(context); UIImage* img = [UIImage imageWithCGImage: imageRef]; CGImageRelease(imageRef); CGContextRelease(context); return img; 

If performSelector returned a value, that would be pretty simple.
But this is not so. Since this seems like a pretty common requirement, I wonder if there is a preferred practice of this.

thanks

+4
source share
1 answer

UIImage * img = [UIImage imageWithCGImage: imageRef]; can only be done in main-thread .. bah ..

Only for target iOS 3.x devices. Starting with iOS 4, UIImage become thread safe. If you need to run iOS 3, the typical behavior would be to pass your CGImageRef back to the main thread and run imageWithCGImage there.

+4
source

All Articles