views:

101

answers:

1

So I know you can get a CGImage from a file using UIImage...

UIImage *img = [UIImage imageNamed:@"name.bmp"];
[img CGImage];

But, is there a way to get a CGImageRef without using a UIImage?

(I am trying this in a static library which doesn't have access to UIKit) I could use other frameworks if necessary, just not UIKit. Would CIImage work? Or NSBitmapImageRep?

+1  A: 

You can get it from NSData:

CGDataProviderRef imgDataProvider = CGDataProviderCreateWithCFData((CFDataRef)[NSData dataWithContentsOfFile:@""]);
CGImageRef image = CGImageCreateWithPNGDataProvider(imgDataProvider, NULL, true, kCGRenderingIntentDefault); // Or JPEGDataProvider

You would have to be certain that the data was a JPEG or a PNG for this to work.

Tom Irving
sweet! Thanks! Do you know if there's a way to do this for a BMP? There's no CGImageCreateWithBMPDataProvider...
OTisler
No, sorry, I think you'll have to go through the UIImage route for that :(
Tom Irving