如何从磁盘上的映像制作CGImageRef [英] How exactly to make a CGImageRef from an image on disk

查看:146
本文介绍了如何从磁盘上的映像制作CGImageRef的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到处寻找无济于事。我正在一个线程中进行一些图像加载,因为UIKit不是线程安全的,我将不得不将图像存储为CGImageRefs,但我无法弄清楚如何做到这一点。我之前没有使用任何Quartz的东西,所以这让我很困惑。基本上我只需要将磁盘中的JPG加载到CGImageRef中。另外对于奖励积分,无论如何都要将GIF加载到CGImageRef中吗?

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 CGImageRefs but I can't figure out how to do this. I haven't played with any of the Quartz stuff before so it's confusing me. Basically I just need to load a JPG from the disk into a CGImageRef. Also for bonus points, is there anyway to load a GIF into a CGImageRef?

推荐答案

gcamp或多或少是正确的,你是在后台线程上使用它非常安全,但是为了回答你的问题,我相信以下内容可行。

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);

还有一个功能jpg图片, CGImageCreateWithJPEGDataProvider

There is also a function for jpg images, CGImageCreateWithJPEGDataProvider.

(确保完成时释放数据提供者和图像)

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

这篇关于如何从磁盘上的映像制作CGImageRef的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆