iPhone上的螺纹绘图

时间:2009-10-04 17:34:21

标签: iphone cocoa-touch multithreading quartz-2d nsoperation

Apples文档指出,一般来说Quartz2D是thread-safe。但是,当在NSOperation期间绘制到图像上下文时,我遇到了崩溃(EXC_BAD_ACCESS)。

这是我目前的设置:

UIGraphicsBeginImageContext(imageSize);
CGContextRef context = UIGraphicsGetCurrentContext();
// drawing code
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

我怀疑崩溃与当前上下文有关,因为UIGraphicsGetCurrentContext文档指出它需要从main thread调用。它是否正确?有没有其他方法来获取图像上下文?

2 个答案:

答案 0 :(得分:4)

各种UIGraphics函数主要是围绕较低级函数的便捷方法。阅读CGGraphicsContext以及如何创建自己的;文档非常有用。

答案 1 :(得分:3)

你已经回答了自己的问题。文档说你必须在主线程上调用UIGraphicsGetCurrentContext(),你没有这样做,你的应用程序崩溃了。 QED。