How do I put a GIF onto an NSPasteboard?
How do I put a GIF onto an NSPasteboard?
- Subject: How do I put a GIF onto an NSPasteboard?
- From: Pete Yandell <email@hidden>
- Date: Sun, 27 Nov 2005 12:46:17 +1100
I'm implementing a NSImageView subclass and want to allow the image
to be dragged out to the Finder to create a GIF file, much the same
way you can drag an image out of a web page in Safari.
I have sample code to put a TIFF representation on the pasteboard,
and I have sample code to generate a GIF representation of an
NSImage, but I'm not sure how to set the pasteboard types correctly
for the GIF. Anyone know how to do this? What about setting the
filename for the dragged GIF file?
The code for dragging a TIFF representation:
- (void)mouseDown:(NSEvent*)event
{
NSPasteboard *board = [NSPasteboard
pasteboardWithName:NSDragPboard];
[board declareTypes:[NSArray arrayWithObject:NSTIFFPboardType]
owner:self];
[board setData:[[self image] TIFFRepresentation]
forType:NSTIFFPboardType];
float x = ([self bounds].size.width - [[self image]
size].width) / 2;
float y = ([self bounds].size.height - [[self image]
size].height) / 2;
[self dragImage:[self image] at:NSMakePoint(x, y)
offset:NSMakeSize(0, 0) event:event pasteboard:board source:self
slideBack:YES];
}
The code for getting a GIF representation:
[image lockFocus];
NSBitmapImageRep* bitmap = [[NSBitmapImageRep alloc]
initWithFocusedViewRect:NSMakeRect(0, 0, width, height)];
NSData* gif = [bitmap representationUsingType:NSGIFFileType
properties:nil];
[bitmap release];
[image unlockFocus];
Cheers,
Pete Yandell
_______________________________________________
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