开发者

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

UIImage* i开发者_Python百科mg = [UIImage imageWithCGImage: imageRef];

can be done in main-thread only.. bah..

Now all my image create functions which are to be run in background thread has to be modified.

Question is how should I change the above line.

Usual steps of creating image were as below.

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

CGContextRelease(context);

return img;

If performSelector returned a value, it would be rather easy.

But it's not. Since this seems rather common requirement, I wonder if there are preferable practice of doing this.

Thank you


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

Only if you want to target iOS 3.x devices. Starting from iOS 4, UIImage became thread-safe. If you need to run on iOS 3, typical behaviour would be to pass your CGImageRef back to the main thread, and have the imageWithCGImage method run there.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜