我的应用突然开始生成大量这种类型的错误:
<Error>: CGContextSetInterpolationQuality: 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.
对于CGContextDrawImage、CGBitmapContextCreateImage等操作也是同样的处理方式。
我显然在做些严重错误的事情,但我不确定是什么。我使用了下面的代码,这是我从别人那里为我的应用程序改编的。它基本上调整图像的大小,考虑到设备的因素。
代码似乎正常工作,我的应用程序也按照预期运行,但我不确定是什么导致了这些看起来相当严重的错误。有人能看出我代码中可能导致这些错误的明显问题吗?
-(UIImage *)resizeImage:(NSString *)imageName {
UIImage *originalImage = [UIImage imageNamed:imageName];
CGRect newRect = CGRectIntegral(CGRectMake(0, 0, originalImage.size.width * myScalingFactor, originalImage.size.height * myScalingFactor));
CGImageRef imageRef = originalImage.CGImage;
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmap = CGBitmapContextCreate(
NULL,
newRect.size.width,
newRect.size.height,
8,
(newRect.size.width * 4),
colorSpace,
kCGImageAlphaPremultipliedLast
);
CGColorSpaceRelease(colorSpace);
CGContextSetInterpolationQuality(bitmap, 3);
CGContextDrawImage(bitmap, newRect, imageRef);
CGImageRef newImageRef = CGBitmapContextCreateImage(bitmap);
UIImage *newImage = [UIImage imageWithCGImage:newImageRef];
CGContextRelease(bitmap);
CGImageRelease(newImageRef);
return newImage;
}