【问题标题】:Null Graphics Context空图形上下文
【发布时间】:2014-04-07 22:27:26
【问题描述】:

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

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 返回无效的图形上下文?

【问题讨论】:

标签: ios uigraphicscontext


【解决方案1】:

正如评论所建议的,答案是传递给UIGraphicsBeginImageContextWithOptionsCGRect 的面积为零。这显然是它无法创建图形上下文的情况。

【讨论】:

  • 我有同样的问题,这就是答案,检查宽度和高度是否不为 0。
猜你喜欢
  • 2010-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-14
  • 2017-11-02
  • 1970-01-01
  • 2011-10-12
  • 1970-01-01
相关资源
最近更新 更多