Re: Getting NSImage from within an NSTextView
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