On Feb 21, 2016, at 6:47 PM, Graham Cox <graham....@bigpond.com> wrote:
> 
> So is there a way, given that if +canInitWithPasteboard: returns YES, to get 
> the (NS)data off the pasteboard in whatever format it’s in, knowing that it’s 
> good for making an image?

You can use [NSImage readableTypesForPasteboard:pasteboard] (a method from the 
NSPasteboardReading protocol) to get the list of UTIs for the types that 
NSImage can import.  Then, you can enumerate over [pasteboard pasteboardItems] 
and, for each item, query -availableTypeFromArray:.  If the item provides one 
of the types that NSImage can import from, you can then query -dataForType: 
with that type.  Not only do you then have the original data, but you have the 
UTI for it, as well.

If more than one item provides a type, then the pasteboard effectively contains 
multiple images.  Presumably, -initWithPasteboard: would only take the first, 
although the modern way, using -[NSPasteboard readObjectsForClasses:options:], 
would give you them all.

All of that said, though, keep in mind that most Mac apps will put a bitmap 
image on the pasteboard as TIFF data, regardless of the original bitmap file 
format.  That is, if an app creates an NSImage from a PNG file and then writes 
it to the pasteboard using -[NSPasteboard writeObjects:], NSImage will store 
TIFF data.  For historical reasons, TIFF is the standard image interchange 
format on OS X.  (If you manually put public.png data on the pasteboard, that 
will survive intact, although the system will _add_ a TIFF version of the same 
image for the sake of compatibility with apps which can only accept TIFF.)

Regards,
Ken


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to