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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With