许多CGContext无效上下文0x0错误iOS 8

pin*_*gin 3 objective-c cgcontext ios ios8

我的应用程序突然开始产生很多这种类型的错误:

<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.
Run Code Online (Sandbox Code Playgroud)

依此类推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;
}
Run Code Online (Sandbox Code Playgroud)

Cla*_*sen 12

CGContextSetInterpolationQuality: invalid context 0x0.表示context传递给的参数CGContextSetInterpolationQuality是空指针(因此内存地址为0x0).

为避免这种情况,您应该检查是否CGBitmapContextCreate返回NULL.如果提供无效的宽度/高度(为零),则会发生这种情况.