• 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: How to get NSImage into an NSMutableAttributedString ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get NSImage into an NSMutableAttributedString ?


  • Subject: Re: How to get NSImage into an NSMutableAttributedString ?
  • From: Rainer Brockerhoff <email@hidden>
  • Date: Mon, 1 Dec 2003 21:20:28 -0200

>From: Bob Miller <email@hidden>
>Date: Mon, 1 Dec 2003 15:54:42 -0500
>
> This may be a simple operation but, I've yet to figure it out and
>haven't been able to find an answer for this one anywhere .I hope
>someone can help. Does anyone know if it is possible to insert an
>NSImage reference into an NSAttributedStrin so that it becomes
>'attached' and gets displayed within the string similar as it would if
>an image file was dragged from the desktop for instance ? Is it even
>possible to insert and NSImage into an NSAttributedString (Mutable that
>is) ?

Here's the general outline.

NSImage* theImage; // this should point at your image
// first make a file wrapper
NSFileWrapper* wrapper =[[[NSFileWrapper alloc] initRegularFileWithContents:
[theImage TIFFRepresentationUsingCompression:NSTIFFCompressionLZW factor:1]] autorelease];
// (change to another representation if you don't want a TIFF)
// set a filename just in case the user copies&pastes this somewhere for saving
// (be sure to use the right extension for the representation)
[wrapper setPreferredFilename:@"theImage.tiff"];
// now make a string with the image attached
NSAttributedString* representedImage = [NSAttributedString attributedStringWithAttachment:
[[[NSTextAttachment alloc] initWithFileWrapper:wrapper] autorelease]];

Now representedImage is a NSAttributedString containing only the image. You can now manipulate this, insert it into some NSTextView, and so forth.

Was that it?

--
Rainer Brockerhoff <email@hidden>
Belo Horizonte, Brazil
"It's extremely unlucky to be superstitious, for no other reason
than it is always unlucky to be colossally stupid." (Stephen Fry)
Weblog: http://www.brockerhoff.net/bb/viewtopic.php
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Drawing complex vector shapes
  • Next by Date: NSWindow delegates
  • Previous by thread: Re: How to get NSImage into an NSMutableAttributedString ?
  • Next by thread: Re: Splitview; keeping one sub-view at constant width when window resizes
  • Index(es):
    • Date
    • Thread