FROM : Fabio Lossotti
DATE : Thu Nov 21 07:15:01 2002
You've got almost everything you need, just pull a JPEG or GIF instead
of a TIFF. Here are some code snippets that should help.
To get the JPEG image:
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:[image TIFFRepresentationUsingCompression:
NSTIFFCompressionLZW factor: 15.0]];
NSData *jpgData = [imageRep representationUsingType:NSJPEGFileType
properties:nil];
(then write the data to the pasteboard)
And for GIFs:
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:[image TIFFRepresentationUsingCompression:
NSTIFFCompressionLZW factor: 15.0]];
NSData *gifData = [imageRep
representationUsingType:NSGIFFileType properties:nil];
(then write the data to the pasteboard)
-FL
--- Timothy Paustian <<email_removed>> wrote:
> I have a view that has several graphics in it. From this I want to be
>
> able to allows users to drag out a jpeg and/or gif to other parts of
> the application or even to other applications. I have this working
> for tiffs and here is the code I use. (Note I know the command key
> thing is a bit non-standard, but it works for what I am trying to do.
>
> How can I modify this code to get me a jpeg or gif?
>
> - (void)mouseDown:(NSEvent *)theEvent
> {
> NSSize dragOffset = NSMakeSize(0.0, 0.0);
> NSPasteboard *pboard;
> unsigned int modifiers = [theEvent modifierFlags];
>
> if(modifiers & NSCommandKeyMask)
> {
> NSRect bounds = [self bounds];
> NSImage *image = [[[NSImage alloc] initWithSize: bounds.size]
> autorelease];
> NSImage *dragImage = [[[NSImage alloc] initWithSize:
> bounds.size] autorelease];
> NSPoint dragPoint = NSMakePoint(0.0, 0.0);
>
> pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
> [pboard declareTypes:[NSArray
> arrayWithObject:NSTIFFPboardType] owner:self];
>
> [image lockFocus];
> [self drawRect:bounds];
> [image unlockFocus];
>
> [pboard setData: [image TIFFRepresentationUsingCompression:
> NSTIFFCompressionLZW factor: 15.0] forType:
> NSTIFFPboardType];
>
> [dragImage setBackgroundColor:[NSColor clearColor]];
> [dragImage lockFocus];
> [image dissolveToPoint: dragPoint fraction: 0.5];
> [dragImage unlockFocus];
>
> [self dragImage:dragImage
> at:bounds.origin
> offset: dragOffset
> event:theEvent
> pasteboard:pboard
> source:self slideBack:YES];
> }
> else
> {
> [super mouseDown:theEvent];
> }
> return;
> }
>
> --
> Cheers,
> Tim
>
> Timothy Paustian
> UW-Madison, Bacteriology
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
DATE : Thu Nov 21 07:15:01 2002
You've got almost everything you need, just pull a JPEG or GIF instead
of a TIFF. Here are some code snippets that should help.
To get the JPEG image:
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:[image TIFFRepresentationUsingCompression:
NSTIFFCompressionLZW factor: 15.0]];
NSData *jpgData = [imageRep representationUsingType:NSJPEGFileType
properties:nil];
(then write the data to the pasteboard)
And for GIFs:
NSBitmapImageRep *imageRep = [NSBitmapImageRep
imageRepWithData:[image TIFFRepresentationUsingCompression:
NSTIFFCompressionLZW factor: 15.0]];
NSData *gifData = [imageRep
representationUsingType:NSGIFFileType properties:nil];
(then write the data to the pasteboard)
-FL
--- Timothy Paustian <<email_removed>> wrote:
> I have a view that has several graphics in it. From this I want to be
>
> able to allows users to drag out a jpeg and/or gif to other parts of
> the application or even to other applications. I have this working
> for tiffs and here is the code I use. (Note I know the command key
> thing is a bit non-standard, but it works for what I am trying to do.
>
> How can I modify this code to get me a jpeg or gif?
>
> - (void)mouseDown:(NSEvent *)theEvent
> {
> NSSize dragOffset = NSMakeSize(0.0, 0.0);
> NSPasteboard *pboard;
> unsigned int modifiers = [theEvent modifierFlags];
>
> if(modifiers & NSCommandKeyMask)
> {
> NSRect bounds = [self bounds];
> NSImage *image = [[[NSImage alloc] initWithSize: bounds.size]
> autorelease];
> NSImage *dragImage = [[[NSImage alloc] initWithSize:
> bounds.size] autorelease];
> NSPoint dragPoint = NSMakePoint(0.0, 0.0);
>
> pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
> [pboard declareTypes:[NSArray
> arrayWithObject:NSTIFFPboardType] owner:self];
>
> [image lockFocus];
> [self drawRect:bounds];
> [image unlockFocus];
>
> [pboard setData: [image TIFFRepresentationUsingCompression:
> NSTIFFCompressionLZW factor: 15.0] forType:
> NSTIFFPboardType];
>
> [dragImage setBackgroundColor:[NSColor clearColor]];
> [dragImage lockFocus];
> [image dissolveToPoint: dragPoint fraction: 0.5];
> [dragImage unlockFocus];
>
> [self dragImage:dragImage
> at:bounds.origin
> offset: dragOffset
> event:theEvent
> pasteboard:pboard
> source:self slideBack:YES];
> }
> else
> {
> [super mouseDown:theEvent];
> }
> return;
> }
>
> --
> Cheers,
> Tim
>
> Timothy Paustian
> UW-Madison, Bacteriology
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus – Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
| Related mails | Author | Date |
|---|---|---|
| Timothy Paustian | Nov 20, 19:45 | |
| Fabio Lossotti | Nov 21, 07:15 | |
| Andrew Zamler-Carh… | Nov 21, 10:22 |






Cocoa mail archive

