究竟如何从磁盘上的图像创建 CGImageRef

发布于 2024-09-15 19:35:26 字数 183 浏览 3 评论 0原文

我到处找遍了都没有结果。我正在线程中加载一些图像,由于 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

暗恋未遂 2024-09-22 19:35:26

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

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

还有一个用于 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.

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)

无风消散 2024-09-22 19:35:26

我认为最简单的方法是使用 UIKit 并使用 UIImage 的 CGImage 属性。

像这样的东西:

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

I think the simplest way is to use UIKit and use the CGImage propriety of UIImage.

Something like that :

UIImage* image = [UIImage imageNamed:@"Your Image.png"];
CGImageRef imageRef = image.CGImage;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文