是否可以在 iPhone 上保存带有 Core Graphics 的图像?

发布于 2024-08-23 05:50:22 字数 618 浏览 2 评论 0原文

以下代码将 PDF 页面转换为 JPEG。它在 Snow Leopard 上按预期运行:

...
//get the image from the bitmap context
CGImageRef image = CGBitmapContextCreateImage(outContext);

//create the output destination
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, kUTTypeJPEG, 1, NULL);

//add the image to the output file
CGImageDestinationAddImage(outfile, image, NULL);
CGImageDestinationFinalize(outfile);
...

针对 iPhone 编译此代码时会失败,因为 iPhone 版本的 Core Graphics 不包含 CGImageDestinationRef。有没有办法使用本机 iPhone 框架和库将 CFImageRef 保存为 jpeg?我能想到的唯一选择是放弃 Core Graphics 并使用 ImageMagick。

The following code converts a PDF page into a JPEG. It runs as expected on Snow Leopard:

...
//get the image from the bitmap context
CGImageRef image = CGBitmapContextCreateImage(outContext);

//create the output destination
CGImageDestinationRef outfile = CGImageDestinationCreateWithURL(fileUrl, kUTTypeJPEG, 1, NULL);

//add the image to the output file
CGImageDestinationAddImage(outfile, image, NULL);
CGImageDestinationFinalize(outfile);
...

This code fails when compiled for iPhone because the iPhone version of Core Graphics does not include CGImageDestinationRef. Is there any way to save CFImageRef to a jpeg using the native iPhone frameworks and libraries? The only alternative I can think of is to ditch Core Graphics and use ImageMagick.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

萌能量女王 2024-08-30 05:50:22
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...
UIImage *myImage = [UIImage imageWithCGImage:image];
NSData *jpgData = UIImageJPEGRepresentation(myImage, 0.9f);
[jpgData writeToFile:...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文