Cocoa touch 在模拟器中创建用于调整UIImage大小的CGImageContext失败

Cocoa touch 在模拟器中创建用于调整UIImage大小的CGImageContext失败,cocoa-touch,ios-simulator,core-graphics,Cocoa Touch,Ios Simulator,Core Graphics,我有一些代码来调整UIImage的大小(在UIImage的类别中),它首先生成一个图像上下文: CGImageRef oldImage = [self CGImage]; CGSize oldSize = [self size]; CGContextRef context = CGBitmapContextCreate(NULL, //Data newSize.width, //Width newSize.height, //Height CGImageGetBitsP

我有一些代码来调整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.
:CGBitmapContextCreate:不支持的参数组合:8个整数位/组件;24位/像素;三分量色彩空间;KCGIMAGEALPHONE;428字节/行。

有人对此有解释吗?如果我没记错的话,它在2.2之前工作得很好,谢谢

我对此知之甚少,但我的猜测是,您的每行字节数参数必须为3*newSize.width,因为图像报告没有alpha组件

如果这不起作用,您可能需要查看以获取更多信息。令人痛心的是,24 bpp没有条目,尽管错误报告了这一点。您可能希望在模拟器和设备中记录相关值,以查看是否存在任何其他差异