Re: Image data from pasteboard?
Re: Image data from pasteboard?
- Subject: Re: Image data from pasteboard?
- From: Graham Cox <email@hidden>
- Date: Tue, 23 Feb 2016 15:29:11 +1100
> On 22 Feb 2016, at 1:30 PM, Ken Thomases <email@hidden> wrote:
>
> On Feb 21, 2016, at 6:47 PM, Graham Cox <email@hidden> 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
>
Thanks, I figured it would be a bit like this. Shame about that TIFF conversion, it’s a pain in the proverbial when moving JPGs and PNGs around.
—Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden