• 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: NSImage in NSAttributedString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage in NSAttributedString


  • Subject: Re: NSImage in NSAttributedString
  • From: Graham Cox <email@hidden>
  • Date: Wed, 12 Nov 2008 22:51:27 +1100


On 12 Nov 2008, at 10:34 pm, Timothy Larkin wrote:

I am building an attributed string for display in a NSTextView. I can include an image in the string by attaching a file wrapper. But what if I have just an NSImage? I know that an image from the clipboard can be inserted in a text view. But how can I do this programatically? Is there a better way than writing the image to a temporary file and then using that file wrapper?


A file wrapper doesn't necessarily imply that there is a file, only that it could become one.

I'm not familiar with attachments, but it looks to me as if NSTextAttachment can be inited with a file wrapper that you create, and you can do that using e.g. -initRegularFileWithContents:, passing it NSData which could be your image data. So it's a bit of a chain of data conversion needed, but it doesn't require you to write a temporary file. When the text is saved as RTFD then the file wrappers you attached will become real files within the RTFD package.

On the other hand, apps such as Mail seem to create temporary files when you add image attachments, so that could be a valid approach also.

At least that's my reading of the docs - someone with more familiarity will undoubtedly jump in and correct me if I've got it wrong ;-)



hth,


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


References: 
 >NSImage in NSAttributedString (From: Timothy Larkin <email@hidden>)

  • Prev by Date: Re: How can I use NSTextField like a button?
  • Next by Date: Re: Drag Tabs, Custom Colors
  • Previous by thread: NSImage in NSAttributedString
  • Next by thread: Re: NSImage in NSAttributedString
  • Index(es):
    • Date
    • Thread