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 (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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to