I have the following code to create a new bitmap graphics context.
NSLog(@"newRect Width %f",newRect.size.width);
NSLog(@"newRect Height %f",newRect.size.height);
NSLog(@"imageRef %@",imageRef);
CGContextRef bitmap = CGBitmapContextCreate(NULL,
newRect.size.width,
newRect.size.height,
CGImageGetBitsPerComponent(imageRef),
0,
CGImageGetColorSpace(imageRef),
CGImageGetBitmapInfo(imageRef));
The newRect.size.width is the result of dividing the original width of UIImage by 2. The newRect.size.height is the result of dividing the original height of UIImage by 2.
But for some UIImages with sizes {3000, 2002},{3024, 4032},{4032, 3024} are okay and returning bitmap context.
But for some UIImages with sizes {1242, 2208}. Normally these are screenshots from my devices and returning NULL value.
Is anyone can help on my issue. Thanks.


I was not able to reproduce the problem. I would suggest to log all incoming parameters and append log to your question. Also look into console log, CGBitmapContextCreate may write something there that may give the insight about the problem.
UPDATED:
The problem you are facing has nothing to do with image size, but with combination of bitmap info/colorspace and bits per component. Here what I got in system log trying to create bitmap context with info you provided:
You can try to use something standard always or in case of failure, e.g.
Or let system choose appropriate context for you: