CGContextSetFillColorWithColor:无效的上下文0x0

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

我得到这个方法的[color setFill]行的错误。 任何想法如何我可以解决它?

+ (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不会创buildgraphics上下文。 这两个image.size.width必须是正数,有限数字。

可能image本身是nil 。 当您将size消息发送到CGSizeZero ,您将返回CGSizeZero