我有这样一段代码给我的图像的色彩,我需要:CGContextFillRects:无效的情况下 - 目标C
- (UIImage*)convertToMask: (UIImage *) image
{
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGRect imageRect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Draw a white background (for white mask)
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 0.9f);
CGContextFillRect(ctx, imageRect);
// Apply the source image's alpha
[image drawInRect:imageRect blendMode:kCGBlendModeDestinationIn alpha:1.0f];
UIImage* outImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outImage;
}
一切正常,在我的第一个观点很好,但是当我添加这对我的详细视图,它给我这个错误(它仍然有效):
CGContextSetRGBFillColor:invalid context 0x0。这是一个严重的错误。此应用程序或其使用的库正在使用无效的上下文,从而导致系统稳定性和可靠性的整体降级。这个通知是礼貌的:请解决这个问题。这将成为即将到来的更新中的致命错误。
CGContextFillRects:无效的上下文0x0。这是一个严重的错误。这个 应用程序或其使用的库正在使用无效的上下文,因此有助于整体降低系统稳定性和可靠性。这个通知是礼貌的:请解决这个问题。它 将成为即将到来的更新中的致命错误。
任何想法如何摆脱这个错误?
谢谢。
编辑:
该行动被调用与零图像。我很容易通过添加条件来修复它。感谢@ipmcc的评论。
- (UIImage*)convertToMask: (UIImage *) image
{
if (image != nil) {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGRect imageRect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Draw a white background (for white mask)
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 0.9f);
CGContextFillRect(ctx, imageRect);
// Apply the source image's alpha
[image drawInRect:imageRect blendMode:kCGBlendModeDestinationIn alpha:1.0f];
UIImage* outImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return outImage;
}else{
return image;
}
}
第三个相同的问题在两天内,第二个今天。 – 2013-08-07 16:17:30
是你的图像'无'? IIRC,如果您将高度,宽度或比例的0传递给'UIGraphicsBeginImageContextWithOptions',上下文将为'nil'。 – ipmcc
@ipmcc是的,由于某种原因该方法被调用一次无图像。通过添加条件可以很容易地解决这个问题。它在我的第一个观点上工作,所以这并没有出现在我的脑海里。谢谢 – adam