Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Lots of invalid context 0x0 errors #1

Open
jdandrea opened this issue May 3, 2012 · 5 comments
Open

Lots of invalid context 0x0 errors #1

jdandrea opened this issue May 3, 2012 · 5 comments

Comments

@jdandrea
Copy link

jdandrea commented May 3, 2012

Any ideas? (Note: I've disabled ARC for these three method files, though the app I'm writing uses ARC.)

May  3 11:21:43 MyMac.local MyApp[62951] <Error>: CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 224 bytes/row.
May  3 11:21:43 MyMac.local MyApp[62951] <Error>: CGContextConcatCTM: invalid context 0x0
May  3 11:21:43 MyMac.local MyApp[62951] <Error>: CGContextSetInterpolationQuality: invalid context 0x0
May  3 11:21:43 MyMac.local MyApp[62951] <Error>: CGContextDrawImage: invalid context 0x0
May  3 11:21:43 MyMac.local MyApp[62951] <Error>: CGBitmapContextCreateImage: invalid context 0x0

Seems to happen after I call -thumbnailImage:transparentBorder:cornerRadius:interpolationQuality:.

@mbcharbonneau
Copy link
Owner

Can you upload a sample image that causes this error please? I'll see what I can do about getting a fix pushed up.

@jdandrea
Copy link
Author

jdandrea commented May 3, 2012

It's an image that I have within my app bundle (the placeholder/default images). I will email a few of them to you. They're pretty small (50x50 png source).

This seems to be the source of all the grief:

CGBitmapContextCreate: unsupported parameter combination: 8 integer bits/component; 32 bits/pixel; 3-component color space; kCGImageAlphaLast; 224 bytes/row.

I've sent the image (and its 2x counterpart) your way, along with code snippets!

@jdandrea
Copy link
Author

jdandrea commented May 3, 2012

More info!

Looks like CGImageGetBitmapInfo returns 3 (instead of 2) for my default images. For the record, it's 8 bits per component, 3 components, color space model 1, and then bitmap info is usually 2, but sometimes 3 (for the default images).

Now, kCGBitmapFloatComponents is 256, and kCGBitmapAlphaInfoMask is 31 ... so this 2/3 is just alpha info ... and thus we come to CGImageAlphaInfo:

2 = kCGImageAlphaPremultipliedLast. The alpha component is stored in the least significant bits of each pixel and the color components have already been multiplied by this alpha value. For example, premultiplied RGBA.

3 = kCGImageAlphaPremultipliedFirst. The alpha component is stored in the most significant bits of each pixel and the color components have already been multiplied by this alpha value. For example, premultiplied ARGB.

Hmm ... I sure hope I deduced all that correctly! Not that I know why one-vs-the-other is not good (I don't).

Another update: It didn't matter. Turns out that my 50x50 icon has alpha already applied (it no longer needs to be, so I will swap that out), but the 100x100 does NOT have alpha applied ... so bitmap info is 2 for that ... and we still get that error. Curiouser and curiouser ...

Per Table 2-1, Pixel formats supported for bitmap graphics contexts, kCGImageAlphaLast is not supported along with 8 bpc and 32 bpp. Hmph. Now how'd my images get THAT way? :)

@jdandrea
Copy link
Author

jdandrea commented May 3, 2012

Eureka! See this SO item, in particular the normalize method.

Once I added that to UIImage+Common, then called it up-front in the various helper methods, all the errors went away! The only other problem now is what to do about the 2x vs 1x images. I can see in the simulator that the 1x images are being used even when in Retina mode.

According to one of the comments over on Björn's blog, "Great code, but it scales down retina graphics to regular resolution." Eek. :(

@rudensm
Copy link

rudensm commented Aug 17, 2012

Any news on this issue? My xcode log screen - http://screencast.com/t/tdaUQu92SxqF I have this errors only running on simulator.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants