4

这是我正在使用的代码摘录:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^
{

    UIGraphicsBeginImageContextWithOptions(irect.size, YES, 0.0 );
    CGContextRef context = UIGraphicsGetCurrentContext();
    if (context == 0)
        NSLog (@"Null Graphics Context") ;
    else
        NSLog (@"OK") ;

    . . . .
    // Various drawing functions

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
  }) ;

我发现对 UIGraphicsGetCurrentContext 的所有其他调用都返回 NULL。我在控制台上收到此消息。

CGContextRestoreGState:无效的上下文 0x0。这是一个严重的错误。此应用程序或它使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体下降。此通知是出于礼貌:请解决此问题。这将成为即将到来的更新中的致命错误。

什么会导致 UIGraphicsGetCurrentContext 返回无效的图形上下文?

4

1 回答 1

16

正如评论所建议的,答案是CGRect传递给UIGraphicsBeginImageContextWithOptions的区域为零。这显然是无法创建图形上下文的情况。

于 2014-04-07T22:45:27.423 回答