• 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
How do I put a GIF onto an NSPasteboard?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Is Apple's singleton sample code correct?
  • Next by Date: Embedding Custom NSView in an NSWindow
  • Previous by thread: Re: NSImage inside NSCell...background image problem [SOLVED]
  • Next by thread: Re: How do I put a GIF onto an NSPasteboard?
  • Index(es):
    • Date
    • Thread