• 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: Getting NSImage from within an NSTextView
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting NSImage from within an NSTextView


  • Subject: Re: Getting NSImage from within an NSTextView
  • From: Heinrich Giesen <email@hidden>
  • Date: Thu, 23 Jun 2005 11:50:37 +0200


On 23.06.2005, at 08:52, email@hidden wrote:

After an image is dropped into a text view, does
anyone know how to get a handle to that image?

the following code shows a possible way to find all images within a textView:

- (IBAction) showImageAttachments:sender
{
    NSAttributedString *attrString = [textView textStorage];
    int length = [attrString length];
    NSRange range = { 0, 0 };
    NSDictionary *attributes;

if( ![attrString containsAttachments] ){ //this view contains no attachments\n\n"
return;
}


while( range.location < length ){
NSTextAttachment *attachment;
attributes = [attrString attributesAtIndex:range.location effectiveRange:&range];
attachment = [attributes objectForKey:NSAttachmentAttributeName];
if( attachment!=nil ){ // we have an attachment
NSFileWrapper *theWrapper = [attachment fileWrapper];
NSString *fileName = [theWrapper preferredFilename];
NSTextAttachmentCell *theCell = [attachment attachmentCell];
NSImage *theImage = [theCell image];
NSArray *theReps = [theImage representations];
// insert code to work with these objects
}
range.location += range.length;
}
}


--
Heinrich Giesen
email@hidden


_______________________________________________ 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
  • Prev by Date: NSTreeController search
  • Next by Date: Re: [still having probs] Re: Printing my document
  • Previous by thread: Getting NSImage from within an NSTextView
  • Next by thread: hyperlink in NSTextView
  • Index(es):
    • Date
    • Thread