Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component iOS [duplicate]

I have the problem with creating context..

I have seen lots of answer but none of this working for me.

I have the following code.

CGSize pixelSize = src_img.size;
pixelSize.width = src_img.scale* src_img.size.width;
pixelSize.height = src_img.scale*src_img.size.height;

size_t d_bytesPerRow = pixelSize.width * 4;
unsigned char *imgData = (unsigned char*)malloc(pixelSize.height * d_bytesPerRow);
CGImageRef imageRef = src_img.CGImage;

CGContextRef context =  CGBitmapContextCreate(imgData,
                                              (size_t)pixelSize.width, (size_t)pixelSize.height, 8, d_bytesPerRow,
                                              CGImageGetColorSpace(imageRef), kCGImageAlphaNone);

In console shows me the error

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

I don't know what to do. Please help

like image 944
user3772344 Avatar asked Jan 18 '26 13:01

user3772344


1 Answers

You are not specifying one of the supported pixel formats. The image's colorspace is apparently an RGB color space. You're specifying kCGImageAlphaNone. Together, that means 3 components per pixel and no padding. Combined with the 8 bits per component that you specified gives 24 bits per pixel.

None of the supported pixel formats allow for 24 bits per pixel. That's another way of saying that none of them supports RGB with kCGImageAlphaNone. If you don't have or want alpha, you need to use either kCGImageAlphaNoneSkipFirst or kCGImageAlphaNoneSkipLast, which means a byte of padding in each pixel bumping it up to 32 bits per pixel.

Also, you're almost always better off specifying NULL for the data parameter and 0 for the bytesPerRow parameter. The former makes memory management much easier. The latter is not only easier, but allows the system to optimize the buffer's alignment.

like image 64
Ken Thomases Avatar answered Jan 21 '26 05:01

Ken Thomases



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!