UIImage-Categories icon indicating copy to clipboard operation
UIImage-Categories copied to clipboard

Lots of invalid context 0x0 errors

Open jdandrea opened this issue 12 years ago • 5 comments

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:.

jdandrea avatar May 03 '12 15:05 jdandrea

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

mbcharbonneau avatar May 03 '12 15:05 mbcharbonneau

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 avatar May 03 '12 18:05 jdandrea

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 avatar May 03 '12 20:05 jdandrea

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. :(

jdandrea avatar May 03 '12 20:05 jdandrea

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

rudensm avatar Aug 17 '12 11:08 rudensm