NSSavePanel、CGImageDestinationFinalize 和 OS X 沙箱

发布于 2024-12-06 02:08:08 字数 574 浏览 11 评论 0原文

我正在使用 NSSavePanel 让用户选择要保存到我的应用程序中的图像。一切工作正常,直到我启用应用程序沙箱和权利。选择已存在的文件时会出现此问题。我的代码是这样的:

// 创建一个指向我们的文件目标的 URL 和一个要保存到的 CGImageDestination。 CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL], (CFStringRef)newUTType, 1, NULL); CGImageDestinationAddImage(imageDestination, cgimage, (CFDictionaryRef)metaData); const bool 结果 = CGImageDestinationFinalize(imageDestination);

它在选择新文件来保存图像时有效,但是当我选择现有文件时,它会在现有文件之外创建奇怪的命名文件,并且无法覆盖目标 url 的内容。更糟糕的是,我没有收到任何错误返回,也无法检测到故障。这是 CoreGraphics 中的错误还是我的代码中的错误?这个问题有什么解决方法吗?

I'm using NSSavePanel to let user select image to save to in my app. Everything worked fine until I enabled app sandboxing and entitlements. The problem occurs with selection of an already existing file. My code is like this:

// Create a URL to our file destination and a CGImageDestination to save to.
CGImageDestinationRef imageDestination = CGImageDestinationCreateWithURL((CFURLRef)[savePanel URL], (CFStringRef)newUTType, 1, NULL);
CGImageDestinationAddImage(imageDestination, cgimage, (CFDictionaryRef)metaData);
const bool result = CGImageDestinationFinalize(imageDestination);

It works when selecting new file to save the image, but when I select existing file it creates strange named file besides existing file and fails to overwrite the contents of destination url. And even worse, I get no error in return and cannot detect the failure. Is this a bug in CoreGraphics or in my code? Is there any workaround for this issue?

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

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

发布评论

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

评论(1

爱的故事 2024-12-13 02:08:08

最后,我发现了核心图形调用的组合,可以覆盖在沙盒环境中工作的现有图像:CGDataConsumerCreateWithURL,然后是CGImageDestinationCreateWithDataConsumer。因此,启用沙箱后,CGImageDestinationCreateWithURL 似乎已损坏(至少在 OS X Lion 10.7.1 中)。

Finally I have discovered combination of core graphics calls to overwrite an already existing image working in sandboxed environment: CGDataConsumerCreateWithURL followed by CGImageDestinationCreateWithDataConsumer. So it seems CGImageDestinationCreateWithURL is broken (at least in OS X Lion 10.7.1) with sandbox enabled.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文