获得无效的上下文错误

时间:2012-07-10 20:52:21

标签: iphone objective-c ios core-graphics

到目前为止我没有太多代码,只有这样才能开始:

UIGraphicsBeginImageContextWithOptions(bounds.size, NO, 0);

    CGContextRef context = UIGraphicsGetCurrentContext();
CGMutablePathRef outerPath;

CGMutablePathRef highlightPath;

CGRect outerRect = rectForRectWithInset(bounds, 1); 

CGRect highlightRect = CGRectMake(outerRect.origin.x,
                                      outerRect.origin.y + 1,
                                      outerRect.size.width,
                                      outerRect.size.height);

然后是有问题的位,当注释掉时,错误消失了:

CGContextSaveGState(context);

CGContextAddPath(context, highlightPath);
CGContextSetFillColorWithColor(context, [[UIColor colorWithWhite:1.0 alpha:0.05]CGColor]);
CGContextFillPath(context);

CGContextRestoreGState(context);

下面就是:

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

1 个答案:

答案 0 :(得分:1)

似乎边界0,0,0,0或者highlightPath存在问题。这些值来自何处?