Sdwebimage: CGBitmapContextCreate: unsupported parameter combination

Created on 26 Apr 2013  路  13Comments  路  Source: SDWebImage/SDWebImage

I'm getting this error message printed to the console for an image on both the head of SDWebImage and 3.2:

CGBitmapContextCreate: unsupported parameter combination: 16 integer bits/component; 64 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedFirst; 480 bytes/row.

I found a StackOverlow post about it, but the image in question doesn't have float values for its size, so I don't think that's the problem.

I created a sample project reproing the issue: https://github.com/MaxGabriel/SDWebImageBug

bug

Most helpful comment

@iFoxxy go to SDWebImageDecoder.m and change this [line 36]:

bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelIndexed);

to this

    bool unsupportedColorSpace = (imageColorSpaceModel == 0
                                  || imageColorSpaceModel == -1
                                  || imageColorSpaceModel == kCGColorSpaceModelIndexed
                                  || imageColorSpaceModel == kCGColorSpaceModelCMYK);

the colorspace for your image is CMYK thats why it was failing. tried it now and its working

All 13 comments

I have the same issue
+1

Same here. Having issues with PNGs

I'm also getting the same error and the file is not getting saved in the document folder instead it is getting cancelled completely. The url is getting stored as cache and it is not telling us whether the image is failed to load or success. Please correct this issue and I have also tried this with saving the images in JPEG format and downloading the PNG images.

<Error>: CGBitmapContextCreate: unsupported parameter combination: 16 integer bits/component; 64 bits/pixel; 3-component color space; kCGImageAlphaPremultipliedFirst; 4960 bytes/row. when load some images, this error message comes out.

I can still reproduce this issue using the latest master (3.6.0), using this image from @MaxGabriel's demo project http://a1.mzstatic.com/us/r1000/066/Purple2/v4/cd/39/63/cd3963aa-d301-8f71-69d2-bef3d54193be/Icon.png. At this point, I have no clue on how to solve this.

@arun057 @chancyWu @obaidjawad
can you replace the code in decodedImageWithImage method in SDWebImageDecoder with this one and try again?

// do not decode animated images
    if (image.images) { return image; }

    CGImageRef imageRef = image.CGImage;

    CGImageAlphaInfo alpha = CGImageGetAlphaInfo(imageRef);
    BOOL anyAlpha = (alpha == kCGImageAlphaFirst ||
                     alpha == kCGImageAlphaLast ||
                     alpha == kCGImageAlphaPremultipliedFirst ||
                     alpha == kCGImageAlphaPremultipliedLast);

    if (anyAlpha) { return image; }

    size_t width = CGImageGetWidth(imageRef);
    size_t height = CGImageGetHeight(imageRef);

    CGContextRef context = CGBitmapContextCreate(NULL, width,
                                                 height,
                                                 CGImageGetBitsPerComponent(imageRef),
                                                 0,
                                                 CGImageGetColorSpace(imageRef),
                                                 kCGBitmapByteOrderDefault | kCGImageAlphaPremultipliedFirst);

    // Draw the image into the context and retrieve the new image, which will now have an alpha layer
    CGContextDrawImage(context, CGRectMake(0, 0, width, height), imageRef);
    CGImageRef imageRefWithAlpha = CGBitmapContextCreateImage(context);
    UIImage *imageWithAlpha = [UIImage imageWithCGImage:imageRefWithAlpha];
                            //[UIImage imageWithCGImage:imageRefWithAlpha scale:image.scale orientation:image.imageOrientation];

    CGContextRelease(context);
    CGImageRelease(imageRefWithAlpha);

    return imageWithAlpha;

any updates on this? Did the code above correct the issue?
tested with this link and it does not produce any warnings or errors in either IOS 7 or 8

Hi! Got the same issue with this JPEG image http://hh.ru/employer-logo/1479899.jpeg
Even @mythodeia 's solution didn't fix it.
Error text: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 40 bits/pixel; 4-component color space; kCGImageAlphaPremultipliedFirst; 1216 bytes/row.

@iFoxxy download the latest build and try again
the code has been changed since that post

@mythodeia with the latest build error still persists... only for the JPEG above.

@iFoxxy go to SDWebImageDecoder.m and change this [line 36]:

bool unsupportedColorSpace = (imageColorSpaceModel == 0 || imageColorSpaceModel == -1 || imageColorSpaceModel == kCGColorSpaceModelIndexed);

to this

    bool unsupportedColorSpace = (imageColorSpaceModel == 0
                                  || imageColorSpaceModel == -1
                                  || imageColorSpaceModel == kCGColorSpaceModelIndexed
                                  || imageColorSpaceModel == kCGColorSpaceModelCMYK);

the colorspace for your image is CMYK thats why it was failing. tried it now and its working

Now it works, thanks!

Aug 25,2015 ,mythodela is so smart,Thank your very much;

Was this page helpful?
0 / 5 - 0 ratings