My app has suddenly started generating a lot of errors of this type:
<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.
and so on for CGContextDrawImage, CGBitmapContextCreateImage, etc.
I'm clearly doing something seriously wrong but I'm not sure what. I'm using the code below which I adapted from someone else for my app. It basically resizes an image taking into account the device.
The code seems to work fine and my app does what is expected but I'm not sure what's causing the errors which seem quite serious. Can anyone see anything obvious in my code that might be causing these errors?
-(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;
}
CGContextSetInterpolationQuality: invalid context 0x0. means that the context parameter passed to CGContextSetInterpolationQuality was a null pointer (hence the memory address 0x0).
To avoid this, you should check if CGBitmapContextCreate returns NULL. This can happen if you supply a invalid width/height (either being zero).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With