Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decodedImageWithImage solve the problem CGBitmapContextCreate #1401

Closed
LilyHZ opened this issue Dec 18, 2015 · 11 comments
Closed

decodedImageWithImage solve the problem CGBitmapContextCreate #1401

LilyHZ opened this issue Dec 18, 2015 · 11 comments
Milestone

Comments

@LilyHZ
Copy link

LilyHZ commented Dec 18, 2015

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 16 bits/pixel; 1-component color space; kCGImageAlphaPremultipliedFirst; 128 bytes/row.
CGContextDrawImage: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.
answer:

  • (UIImage *)decodedImageWithImage:(UIImage *)image {
    @autoreleasepool{
    // do not decode animated images
    if (image.images) { return image; }

    UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale); {
        CGRect imageRect = (CGRect){ CGPointZero, image.size };
        CGRect borderRect = CGRectInset(imageRect, 1, 1);
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:borderRect
                                                   byRoundingCorners:UIRectCornerAllCorners
                                                         cornerRadii:CGSizeMake(0, 0)];
        [path addClip];
        [image drawAtPoint:CGPointZero];
    }
    UIImage *roundedImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return roundedImage;
    

    }

@mythodeia
Copy link
Contributor

@LilyHZ are you using the latest version? the code you have posted is not in the decodedImageWithImage method

@a13xb
Copy link

a13xb commented Jan 13, 2016

@mythodeia I see the same with 3.7.4 decoding a PNG image:

CGBitmapContextCreate: unsupported parameter combination:
    16 integer bits/component;
    64 bits/pixel;
    RGB color space model; kCGImageAlphaPremultipliedFirst;
    1024 bytes/row.
Valid parameters for RGB color space model are:
    16  bits per pixel,      5  bits per component,      kCGImageAlphaNoneSkipFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaNoneSkipFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaNoneSkipLast
    32  bits per pixel,      8  bits per component,      kCGImageAlphaPremultipliedFirst
    32  bits per pixel,      8  bits per component,      kCGImageAlphaPremultipliedLast
    64  bits per pixel,      16 bits per component,      kCGImageAlphaPremultipliedLast
    64  bits per pixel,      16 bits per component,      kCGImageAlphaNoneSkipLast
    128 bits per pixel,      32 bits per component,      kCGImageAlphaNoneSkipLast |kCGBitmapFloatComponents
    128 bits per pixel,      32 bits per component,      kCGImageAlphaPremultipliedLast |kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.

@mythodeia
Copy link
Contributor

@a13xb can you please share that image?

@a13xb
Copy link

a13xb commented Jan 13, 2016

@mythodeia 1

@mythodeia
Copy link
Contributor

@a13xb i will take a look at it thanks

@mythodeia
Copy link
Contributor

the error you are getting is:
unsupported parameter combination: 64 bpp RGB color space model; kCGImageAlphaPremultipliedFirst

according to the following table:
this combination is not supported.

check

@a13xb
Copy link

a13xb commented Jan 13, 2016

@mythodeia Yes, it's not supported, but it happens when SDWebImage creates output context with the wrong pixel format, taking some parameters from input image, hardcoding other parameters, so sometimes they don't match.

Moreover, this image used to work on previous versions of SDWebImage, so it's definitely a regression.

@mythodeia
Copy link
Contributor

@a13xb i will take a closer look later today. 👍

@mythodeia mythodeia reopened this Jan 13, 2016
@mythodeia
Copy link
Contributor

@a13xb if you replace CGImageGetBitsPerComponent(imageRef) with 8 it works fine. but i cannot hardcode this for these kind of images. A better solution would be to check if the bits per component result in an unsupported combination and if it does then roll back to hardcoded 8.
pull requests are always welcome :P

@mythodeia
Copy link
Contributor

@a13xb does this pull solve your issues? #1496

mythodeia added a commit that referenced this issue Mar 17, 2016
fixes  CGContextDrawImage: invalid context 0x0
#1401
#1454
#1457
@mythodeia
Copy link
Contributor

fixed #1496

@bpoplauschi bpoplauschi added this to the 3.7.6 milestone Mar 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants