gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 06:21:39 24 4
gpt4 key购买 nike

我的应用程序突然开始生成大量此类错误:

<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;
}

最佳答案

CGContextSetInterpolationQuality:无效上下文 0x0。 表示传递给 CGContextSetInterpolationQualitycontext 参数是一个空指针(因此内存地址为 0x0)。

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

关于ios - 许多 CGContext 无效上下文 0x0 错误 iOS 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26567992/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com