开发者

Mac OSX / cocoa - getting location path string with raw data for a NSPasteBoard item

开发者 https://www.devze.com 2023-04-08 02:14 出处:网络
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 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 st开发者_如何学JAVAringForType here]


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号