到目前为止,我没有太多代码,仅此开始:
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();
最佳答案
似乎是边界0,0,0,0或highlightPath有问题。这些价值从何而来?
关于iphone - 获取无效的上下文错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11421749/