Re: Convert PICT to NSImage (SOLVED)
Re: Convert PICT to NSImage (SOLVED)
- Subject: Re: Convert PICT to NSImage (SOLVED)
- From: Ian was here <email@hidden>
- Date: Tue, 28 Jun 2005 16:13:51 -0700 (PDT)
I believe this is the "final" solution to this
problem. It addresses the issue brought up by Douglas,
and seems to work great!
NSFileWrapper *fileWrapper = [[[NSFileWrapper alloc]
initRegularFileWithContents:[pictImage
TIFFRepresentation]] autorelease];
NSTextAttachment *textAttachment = [[[NSTextAttachment
alloc] initWithFileWrapper:fileWrapper] autorelease];
[fileWrapper setPreferredFilename:@"myImage.tiff"];
[[pText textStorage]
appendAttributedString:[NSAttributedString
attributedStringWithAttachment:textAttachment]];
Thanks for all your help!!!!
--- Ian was here <email@hidden> wrote:
> You've raised a good point here. I get an exception
> when I try to drag it around the text view.
> Unfortunately, this was the only way I found to get
> the image to actually show up.
>
> The pict data itself won't go into a text view. It
> must first be converted to an image
> (NSPICTImageRep).
> The NSFileWrapper wants data. I suppose I could
> somehow extract the image's bitmap data and feed it
> to
> the file wrapper.
>
>
>
> --- Douglas Davidson <email@hidden> wrote:
>
> >
> > On Jun 28, 2005, at 9:32 AM, Ian was here wrote:
> >
> > > NSTextAttachment *textAttachment =
> > [[NSTextAttachment
> > > alloc] init];
> > >
> > > NSTextAttachmentCell *attCell =
> > > [[[NSTextAttachmentCell alloc]
> > > initImageCell:pictImage] autorelease];
> > >
> > > [textAttachment setAttachmentCell:attCell];
> > >
> > > [[textView textStorage]
> > > appendAttributedString:[NSAttributedString
> > > attributedStringWithAttachment:textAttachment]];
> > >
> >
> > Bear in mind that an NSTextAttachment has two
> > principal components:
> > first, the NSFileWrapper, which represents the
> model
> > portion--that
> > is, the actual attached file; second, the
> > NSTextAttachmentCell, which
> > represents the view portion--that is, the drawing
> > that represents
> > that file in the text.
> >
> > By default--when you drag a file into a text view,
> > for example--the
> > text system will create the cell based on the
> > contents or type of the
> > file, usually either by interpreting it as an
> image,
> > or by finding an
> > icon for it.
> >
> > However, it is certainly possible to decouple
> these
> > two components,
> > and to set a custom image or even a whole custom
> > cell without regard
> > for the contents of the attached file. This is
> what
> > you have done,
> > and it is an appropriate solution in many cases.
> >
> > You must keep in mind, however, that if the text
> is
> > selected and
> > copied, then what is copied over is the contents
> of
> > the attached
> > file, not any custom image that you may have set
> on
> > a cell, or custom
> > cell. Therefore, if you want the attachment to be
> > able to be copied,
> > you must give it an NSFileWrapper to represent it
> in
> > the persistent
> > representation used on the pasteboard.
> >
> > Douglas Davidson
> >
> >
>
>
>
>
> ____________________________________________________
>
> Yahoo! Sports
> Rekindle the Rivalries. Sign up for Fantasy Football
>
> http://football.fantasysports.yahoo.com
> _______________________________________________
> Do not post admin requests to the list. They will be
> ignored.
> Cocoa-dev mailing list
> (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
>
> This email sent to email@hidden
>
____________________________________________________
Yahoo! Sports
Rekindle the Rivalries. Sign up for Fantasy Football
http://football.fantasysports.yahoo.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden