究竟如何从磁盘上的图像创建 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
gcamp 或多或少是正确的,您在后台线程上使用它是非常安全的,但是为了回答您的问题,我相信以下内容会起作用。
还有一个用于 jpg 图像的函数,
CGImageCreateWithJPEGDataProvider
。(完成后请务必释放数据提供者和图像)
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.
There is also a function for jpg images,
CGImageCreateWithJPEGDataProvider
.(be sure to release the data provider and image when done)
我认为最简单的方法是使用 UIKit 并使用 UIImage 的 CGImage 属性。
像这样的东西:
I think the simplest way is to use UIKit and use the
CGImage
propriety ofUIImage
.Something like that :