CGContextSetFillColorWithColor:无效的上下文0x0 [英] CGContextSetFillColorWithColor: invalid context 0x0
问题描述
CGContextSetFillColorWithColor:无效的上下文0x0。这是一个严重的错误。该应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降低。此通知是礼貌的:请解决此问题。它将成为即将到来的更新中的致命错误。
CGContextSetFillColorWithColor: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
我从此方法的[color setFill]行收到错误。关于如何解决它的任何想法?
I'm getting the error from the [color setFill] line of this method. Any ideas on how I can resolve it?
+ (UIImage *)fillImage:(UIImage*)image withColor:(UIColor *)color
{
// begin a new image context, to draw our colored image onto
UIGraphicsBeginImageContextWithOptions(image.size, NO, [[UIScreen mainScreen] scale]);
// get a reference to that context we created
CGContextRef context = UIGraphicsGetCurrentContext();
// set the fill color
[color setFill];
// translate/flip the graphics context (for transforming from CG* coords to UI* coords
CGContextTranslateCTM(context, 0, image.size.height);
CGContextScaleCTM(context, 1.0, -1.0);
// set the blend mode to overlay, and the original image
CGContextSetBlendMode(context, kCGBlendModeOverlay);
CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
//if(overlay) CGContextDrawImage(context, rect, img.CGImage);
// set a mask that matches the shape of the image, then draw (overlay) a colored rectangle
CGContextClipToMask(context, rect, image.CGImage);
CGContextAddRect(context, rect);
CGContextDrawPath(context,kCGPathFill);
// generate a new UIImage from the graphics context we drew onto
UIImage *coloredImg = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//return the color-burned image
return coloredImg;
}
推荐答案
您的 image.size
无效,因此 UIGraphicsBeginImageContextWithOptions
未创建图形上下文。 image.size.width
都必须为正数,有限数字。
Your image.size
isn't valid, so UIGraphicsBeginImageContextWithOptions
isn't creating a graphics context. Both image.size.width
must be positive, finite numbers.
可能 image
本身是 nil
。当您将 size
消息发送到 nil
时,您将返回 CGSizeZero
。
Possibly image
itself is nil
. When you send the size
message to nil
, you get back CGSizeZero
.
这篇关于CGContextSetFillColorWithColor:无效的上下文0x0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!