How to make CGImageRef from disk image exactly

I looked around everywhere, but to no avail. I am doing image loading in a stream, and since UIKit is not thread safe, I will have to store the images as CGImageRefs, but I cannot figure out how to do this. I did not play with someone from quartz, so it bothers me. Basically, I just need to load the jpg from disk into CGImageRef. Also, for bonus points, does it matter to load GIFs into CGImageRef?

+6
iphone gif jpeg quartz-graphics cgimage
source share
2 answers

gcamp is more or less correct, you may well use this in the background thread, but to answer your question, I believe the following will work.

CGDataProviderRef dataProvider = CGDataProviderCreateWithFilename("file"); CGImageRef image = CGImageCreateWithPNGDataProvider(dataProvider, NULL, NO, kCGRenderingIntentDefault); 

There is also a function for jpg images, CGImageCreateWithJPEGDataProvider .

(do not forget to free the data and image provider when this is done)

+29
source share

I think the easiest way is to use UIKit and use CGImage correct UIImage .

Something like that:

 UIImage* image = [UIImage imageNamed:@"Your Image.png"]; CGImageRef imageRef = image.CGImage; 
+8
source share

All Articles