Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone cannot create CGBitmapContext

I have a problem with creating a CGBitmapContext.

CGContextRef bitmapContext = CGBitmapContextCreate(nil, imageSize.width, imageSize.height, 8, imageSize.width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaNoneSkipFirst)

When I run my application normally it works. But when I run it in my 'Test application' (a running app that will perform my tests) the context is logged as (null) and I get the following errors:

<Error>: CGContextSetFillColorWithColor: invalid context 0x0
<Error>: CGContextFillRects: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGContextDrawImage: invalid context 0x0
<Error>: CGBitmapContextCreateImage: invalid context 0x0

My application doesn't crash. But apparently there is something wrong. (I know the errors are created by calling those methods with a nil context).

like image 765
Mats Stijlaart Avatar asked Dec 14 '10 11:12

Mats Stijlaart


1 Answers

This error often appears when the size of the bitmap you're trying to create is CGSizeZero. Check the actual value of imageSize.

Besides, you leak the CGColorSpaceRef you pass into the function.

like image 60
Costique Avatar answered Oct 05 '22 00:10

Costique