Mac OSX / cocoa - 获取带有 NSPasteBoard 项目的原始数据的位置路径字符串
我有一个应用程序,允许我将项目从网络浏览器拖动到应用程序停靠图标。
当我从网络上拖动图像并获取原始数据时 [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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
粘贴板上的所有内容都不是由其所有者(复制到其中的应用程序)放置的。
在粘贴板上查找
NSFilenamesPboardType
和/或NSURLPboardType
。如果它们不存在,则仅复制图像,没有路径或 URL。这是完全可能且有效的,就像从预览或图像编辑器复制图像的一部分一样,应用程序也完全有可能不将路径或 URL 放在粘贴板上,因此不要期望图像必然带有路径或 URL。
呃?您是说当您请求某种类型的字符串时,您返回的字符串是
@"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/orNSURLPboardType
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.
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 askUTTypePNG
, 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 astringForType:
message with that type.