Re: The right way to put a JPEG, PNG, GIF, etc. onto the pasteboard
Re: The right way to put a JPEG, PNG, GIF, etc. onto the pasteboard
- Subject: Re: The right way to put a JPEG, PNG, GIF, etc. onto the pasteboard
- From: email@hidden
- Date: Tue, 9 Apr 2002 17:14:24 -0700
Well, I've partially answered my own question:
There are standard pasteboard types for TIFF, PICT, PDF and EPS. But
there aren't any (or at least, they're not documented in NSPasteboard's
doc) for JPEG, PNG, GIF, and other such types.
So the question is, what's the best way to represent these image
types on the pasteboard?
Turns out wrapping the image data into an attributed string makes
TextEdit like it, perhaps unsurprisingly. However, other apps that I'd
like to recognize the data (GraphicConverter, for example) still don't.
If anybody has any further ideas, let me know. Thanks!
By the way, my code as it now stands is:
NSFileWrapper *wrap = [[NSFileWrapper alloc]
initRegularFileWithContents:data];
NSMutableDictionary *wrapDict = [NSMutableDictionary dictionary];
NSTextAttachment *attachment;
NSAttributedString *attrStr;
NSData *rtfData;
[wrapDict setObject:[NSNumber
numberWithUnsignedLong:FOUR_CHAR_CODE('SSct')]
forKey:NSFileHFSCreatorCode];
[wrapDict setObject:[NSNumber
numberWithUnsignedLong:FOUR_CHAR_CODE('JPEG')] forKey:NSFileHFSTypeCode];
[wrapDict setObject:NSFileTypeRegular forKey:NSFileType];
[wrapDict setObject:[[wrap fileAttributes]
objectForKey:NSFilePosixPermissions] forKey:NSFilePosixPermissions];
[wrap setFileAttributes:wrapDict];
[wrap setPreferredFilename:@"clipboard.jpg"];
[pasteboard writeFileWrapper:wrap];
attachment = [[NSTextAttachment alloc] initWithFileWrapper:wrap];
attrStr = [NSAttributedString
attributedStringWithAttachment:attachment];
rtfData = [attrStr RTFDFromRange:NSMakeRange(0, [attrStr length])
documentAttributes:nil];
[pasteboard addTypes:[NSArray arrayWithObjects:NSRTFDPboardType,
nil] owner:nil];
[pasteboard set
Data:rtfData forType:NSRTFDPboardType];
[wrap release];
Ben Haller
Stick Software
_______________________________________________
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.