views:

625

answers:

1

I've got some code to resize a UIImage (in a category to UIImage), that first generates an Image Context:

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

On the device, this code works well, but on the simulator it fails with the following error:

<Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component colorspace; kCGImageAlphaNone; 428 bytes/row.

Does anyone have an explanation for this? If I remember correctly, it worked fine prior to 2.2 Thanks!

+2  A: 

I know very little about this, but my wild guess would be that your Bytes Per Row argument needs to be 3 * newSize.width since the image is reporting that there's no alpha component.

If that doesn't work, you might want to look at the Quartz 2D Programming Guide's Supported Pixel Formats for more info. What's distressing is that there are no entries for 24 bpp, even though that's what's being reported by the error. You may want to log the relevant values in both the simulator and the device to see if there are any other discrepancies.

Martin Gordon