How exactly to make a CGImageRef from an image on disk

后端 未结 2 524
忘了有多久
忘了有多久 2020-12-14 05:51

I\'ve looked around everywhere to no avail. I\'m doing some image loading in a thread and since UIKit is not thread safe I\'m going to have to store the images as CGImageRef

2条回答
  •  星月不相逢
    2020-12-14 05:57

    gcamp is more or less correct, you are pretty safe to use this on a background thread, but to answer your question, I believe the following would work.

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

    There is also a function for jpg images, CGImageCreateWithJPEGDataProvider.

    (be sure to release the data provider and image when done)

提交回复
热议问题