Mac OSX / cocoa - 获取带有 NSPasteBoard 项目的原始数据的位置路径字符串

发布于 2024-12-06 04:34:41 字数 399 浏览 1 评论 0原文

我有一个应用程序,允许我将项目从网络浏览器拖动到应用程序停靠图标。

当我从网络上拖动图像并获取原始数据时 [pBoardItem dataForType:NSPasteboardTypePNG]; 我得到了我需要的原始图像数据,但我还需要知道拍摄图像形式的位置(即 http://www.somedomain.com/somedir/someimage.png )或者如果是本地的(/Users/somedude/photos/myphoto.png)。

如何获取路径位置信息?

提前致谢。

[编辑**删除了我在此处对 stringForType 所做的错误评论]

I have an app which allows me to drag items from my web browser to the app dock icon.

When I drag an image from the web and get is raw data with [pBoardItem dataForType:NSPasteboardTypePNG];
I get the raw image data which I need but I also need to know the location of the image form where it was taken (ie. http://www.somedomain.com/somedir/someimage.png ) OR if its local (/Users/somedude/photos/myphoto.png).

How do I get the path location information?

Thanks in advance.

[EDIT** removed an erroneous comment I made regarding stringForType here]

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

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

发布评论

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

评论(1

空城之時有危險 2024-12-13 04:34:41

粘贴板上的所有内容都不是由其所有者(复制到其中的应用程序)放置的。

在粘贴板上查找 NSFilenamesPboardType 和/或 NSURLPboardType

如果它们不存在,则仅复制图像,没有路径或 URL。这是完全可能且有效的,就像从预览或图像编辑器复制图像的一部分一样,应用程序也完全有可能不将路径或 URL 放在粘贴板上,因此不要期望图像必然带有路径或 URL。

当我使用 stringForType: 函数时,我只得到 public.png (粘贴板临时给它起的名称)。

呃?您是说当您请求某种类型的字符串时,您返回的字符串是 @"public.png" 吗?

如果是这样,那与粘贴板上的图像无关; @"public.png" 将是粘贴板的内容。也许您自己刚刚将“public.png”复制到剪贴板?

如果您的意思是检索 @"public.png" 类型的字符串,(1) 这不是临时名称,而是 UTI 对于 PNG,(2) 您应该使用命名常量,例如 kUTTypePNG ,优先于硬编码文字,并且 (3) 该类型的值永远不应该是字符串。我不希望从该类型的 stringForType: 消息中获得任何有用的信息。

Nothing's on the pasteboard that wasn't put there by its owner (the app that copied to it).

Look for NSFilenamesPboardType and/or NSURLPboardType on the pasteboard.

If they aren't there, only an image was copied, without a path or URL. This is completely possible and valid, as in the case of a section of an image copied from Preview or an image editor, and it's also completely possible for an application to simply not put the path or URL on the pasteboard, so don't expect that an image will necessarily come with a path or URL.

when I use the stringForType: function I only get public.png (the name pasteboard gave it temporarily).

Er? Are you saying that when you asked for a string for some type, the string you got back was @"public.png"?

If so, that has nothing to do with an image on the pasteboard; @"public.png" would be the contents of the pasteboard. Perhaps you had just copied “public.png” to the clipboard yourself?

If you meant that you retrieved a string for the type @"public.png", (1) that isn't a temporary name, it's the UTI for PNG, (2) you should use the named constants, such as kUTTypePNG, in preference to hard-coded literals, and (3) the value for that type should never be a string. I wouldn't expect to get anything useful from a stringForType: message with that type.

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