Ios CGContextSetFillColorWithColor:无效上下文0x0
CGContextSetFillColorWithColor:上下文0x0无效。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误 我从这个方法的[color setFill]行得到错误。有没有办法解决这个问题Ios CGContextSetFillColorWithColor:无效上下文0x0,ios,objective-c,core-graphics,Ios,Objective C,Core Graphics,CGContextSetFillColorWithColor:上下文0x0无效。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。此通知是出于礼貌:请解决此问题。这将成为即将进行的更新中的致命错误 我从这个方法的[color setFill]行得到错误。有没有办法解决这个问题 + (UIImage *)fillImage:(UIImage*)image withColor:(UIColor *)color { // begin a n
+ (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;
}
您的
图像.size
无效,因此UIGraphicsBeginImageContextWithOptions
未创建图形上下文。image.size.width
和image.size.height
都必须是正的有限数
可能
image
本身是nil
。当您将size
消息发送到nil
时,您会返回CGSizeZero
图像的值是多少。size?它可能无效,并导致UIGraphicsBeginImageContextWithOptions
无法创建图形上下文。有趣。是{0,0}。也许是使用这个方法有问题?+(UIImage*)imageNamed:(NSString*)name with color:(UIColor*)color{//加载图像返回[UIImage fillImage:[UIImage imageNamed:name]with color:color];}@robmayoff-将您的问题作为答案提交,我将其标记为解决方案。事实证明,在某些情况下,我的应用程序试图将该方法用于nil图像。