• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Image data from pasteboard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Image data from pasteboard?


  • Subject: Re: Image data from pasteboard?
  • From: Ken Thomases <email@hidden>
  • Date: Sun, 21 Feb 2016 20:30:47 -0600

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


_______________________________________________

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


  • Follow-Ups:
    • Re: Image data from pasteboard?
      • From: Graham Cox <email@hidden>
References: 
 >Image data from pasteboard? (From: Graham Cox <email@hidden>)

  • Prev by Date: UI to allow user to scale and crop image within a circle
  • Next by Date: Best way to fade in full-screen view controller on iOS?
  • Previous by thread: Image data from pasteboard?
  • Next by thread: Re: Image data from pasteboard?
  • Index(es):
    • Date
    • Thread