我有一些代码来调整 UIImage 的大小(在 UIImage 的类别中),首先生成一个图像上下文:
CGImageRef oldImage = [self CGImage];
CGSize oldSize = [self size];
CGContextRef context = CGBitmapContextCreate(NULL, //Data
newSize.width, //Width
newSize.height, //Height
CGImageGetBitsPerComponent(oldImage), // Bits per Component
4 * newSize.width, //Bytes per Row
CGImageGetColorSpace(oldImage), //Color Space
CGImageGetBitmapInfo(oldImage)); //Info
在设备上,此代码运行良好,但在模拟器上失败,并出现以下错误:
<Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component colorspace; kCGImageAlphaNone; 428 bytes/row.
有人对此有解释吗?如果我没记错的话,在 2.2 之前它工作得很好,谢谢!
最佳答案
我对此知之甚少,但我的疯狂猜测是您的“每行字节数”参数需要为 3 * newSize.width,因为图像报告没有 alpha 分量。
如果这不起作用,您可能需要查看 Quartz 2D Programming Guide's Supported Pixel Formats了解更多信息。令人苦恼的是,没有 24 bpp 的条目,尽管错误报告的是 24 bpp。您可能需要在模拟器和设备中记录相关值,以查看是否存在任何其他差异。
关于cocoa-touch - 创建 CGImageContext 来调整 UIImage 大小在模拟器中失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/476597/