CGBitmapContextCreate: unsupported combination of parameters

I get this error when creating a raster context:

CGBitmapContextCreate: unsupported combination of parameters: 8 integer bits / component; 24 bit / pixel; 3-component color space; kCGImageAlphaNone; 7936 bytes / line.

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 2626, height 3981. I leave bytesPerRow to zero so that it is automatically calculated for me, and he chose 7936 himself.

So where on earth is there inconsistency? It drives me crazy.

+7
source share
4 answers

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

+16
source

CGBitmapContextCreate: unsupported combination of parameters: 8 integer bits / component; 24 bit / pixel; 3-component color space; kCGImageAlphaNone; 7936 bytes / line.

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

+6
source
Heinrich gave you a good answer to this question. I just thought that I was proposing my specific case as an alternative to the answers of the tarmins. The problem with this answer is that it does not solve the problem if you want an alpha channel to be present. When I ran into this problem, I used Trevor Harmon's UIImage + Alpha category. In the code, I found this comment:
 // The bitsPerComponent and bitmapInfo values are hard-coded to prevent an "unsupported parameter combination" error 

Now this hard-fix was in one of the methods that CGBitmapContextCreate , but not what followed. So for me it is just a question to follow the author’s own advice to fix the problem with one of his other methods;)

It is clear that some part of CGBitmapInfo does not receive the correct transfer from the image in question, although why I do not know.

Therefore, use these constants in bitmapInfo if you are working with an alpha channel: kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst

Otherwise, I would like to point out this really useful class if you are dealing with alias problems!

(It is also worth mentioning that this problem only appeared in Xcode 6 ....)

+2
source

I'm not sure if this will help anyone or not, I just ran into a similar problem and still try, but no luck.

My problem:

 CCLabelTTF *header_txt = [CCLabelTTF labelWithString:header fontName:fontname fontSize:header_fontsize dimensions:CGSizeMake(header_fontsize*9, txt_h) hAlignment:kCCTextAlignmentLeft vAlignment:kCCVerticalTextAlignmentCenter]; 

With an error:

<Error>: CGBitmapContextCreate: unsupported combination of parameters: 8 integer bits / component; 8 bit / pixel; 1-component color space; kCGImageAlphaNone; 2147483648 bytes / string.

Then I found an error in that header_fontsize is not assigned any values ​​(because I mistakenly encode using header_fontsize). The error is here: dimensions:CGSizeMake(header_fontsize*9, txt_h) with header_fontsize unassigned to any value (this is not 0; assigning header_fontsize = 0 is still normal); reassigning the value of header_fontsize problem.

I hope this helps someone in a similar case, for example, in the case of Sprite.

+1
source

All Articles