Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGBitmapContextCreate: unsupported parameter combination

I'm getting this error when creating a bitmap context:

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component color space; kCGImageAlphaNone; 7936 bytes/row.

Here's the code (note that the context is based on the parameters of an existing CGImage:

context = CGBitmapContextCreate(NULL,
                                (int)pi.bufferSizeRequired.width,
                                (int)pi.bufferSizeRequired.height,
                                CGImageGetBitsPerComponent(imageRef),
                                0,
                                CGImageGetColorSpace(imageRef),
                                CGImageGetBitmapInfo(imageRef));

Width is 2626, height is 3981. I've leaving bytesPerRow at zero so that it gets calculated automatically for me, and it's chosen 7936 of its own accord.

So, where on Earth is the inconsistency? It's driving me nuts.

like image 408
tarmes Avatar asked Nov 23 '12 10:11

tarmes


3 Answers

For reasons that I don't understand I solved this by setting the BitmapInfo parameter to kCGImageAlphaNoneSkipLast.

like image 111
tarmes Avatar answered Dec 05 '22 07:12

tarmes


CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 24 bits/pixel; 3-component color space; kCGImageAlphaNone; 7936 bytes/row.

In the Quartz 2D Programming documentation is a list of the supported pixel formats. The 8/3/24 combination is not supported but 8/3/32 is, independent of using alpha or not.

like image 36
Heinrich Giesen Avatar answered Dec 05 '22 07:12

Heinrich Giesen


Heinrich gave you a good background to the answer. Just thought I'd offer up my specific case, as an alternative to tarmes' answer. The problem with that answer is that it doesn't solve the issue if you want an alpha channel present. I was using a category called UIImage+Alpha by Trevor Harmon when I encountered this issue. In the code I found this comment:

// The bitsPerComponent and bitmapInfo values are hard-coded to prevent an "unsupported parameter combination" error

Now this hardcoded fix was in one of the methods calling CGBitmapContextCreate, but not the one following it. So for me it was simply a matter of following the author's own advice to fix the problem in one of his other methods ;)

Clearly some part of the CGBitmapInfo is not getting passed correctly from the image in question, though why I don't know.

So use these constants in the bitmapInfo if you're working with the alpha channel: kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst

Otherwise, I'd just like to point out it's a really useful class if you're dealing with aliasing issues!

(Also, worth mentioning this problem only turned up in Xcode 6....)

like image 20
sinewave440hz Avatar answered Dec 05 '22 08:12

sinewave440hz