开发者

Threaded drawing on the iPhone

Apples documentation states that in general Quartz2D is thread-safe. However when drawing to an image context during a NSOperation I'm experiencing crashes (EXC_BAD_ACCESS).

This is my current setup:

UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing code
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext开发者_开发问答();

I suspect the crashes are related to the current context as the UIGraphicsGetCurrentContext docu states that it needs to be called from the main thread. Is this correct? Are there any other ways to get the image context?


The various UIGraphics functions are mostly just convenience methods around the lower-level functions. Read up CGGraphicsContext and how to create your own; the documentation is very helpful.


You've answered your own question. The docs say you have to call UIGraphicsGetCurrentContext() on the main thread, you're not doing so, and your app is crashing. QED.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜