FROM : Andrew Zamler-Carhart
DATE : Thu Nov 21 10:22:01 2002
Folks,
I would only comment that you might want to specify the compression
factor when creating a JPEG image. Rather than passing nil for the
second argument of representationUsingType:properties:, you can pass in
a dictionary where the NSImageCompressionFactor is an NSNumber with a
float value ranging from 0.0 to 1.0, where 0.0 yields a small,
low-quality image and 1.0 a large, high-quality image. I've found that
0.9 works well for my purposes. The default setting creates rather poor
quality images.
NSDictionary *properties = [NSDictionary dictionaryWithObject:
[NSNumber numberWithFloat: 0.9] forKey: NSImageCompressionFactor];
NSData *jpgData = [imageRep representationUsingType: NSJPEGFileType
properties: properties];
Hope this helps,
Andrew
On Thursday, November 21, 2002, at 07:14 AM, Fabio Lossotti wrote:
> 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
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
DATE : Thu Nov 21 10:22:01 2002
Folks,
I would only comment that you might want to specify the compression
factor when creating a JPEG image. Rather than passing nil for the
second argument of representationUsingType:properties:, you can pass in
a dictionary where the NSImageCompressionFactor is an NSNumber with a
float value ranging from 0.0 to 1.0, where 0.0 yields a small,
low-quality image and 1.0 a large, high-quality image. I've found that
0.9 works well for my purposes. The default setting creates rather poor
quality images.
NSDictionary *properties = [NSDictionary dictionaryWithObject:
[NSNumber numberWithFloat: 0.9] forKey: NSImageCompressionFactor];
NSData *jpgData = [imageRep representationUsingType: NSJPEGFileType
properties: properties];
Hope this helps,
Andrew
On Thursday, November 21, 2002, at 07:14 AM, Fabio Lossotti wrote:
> 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
> _______________________________________________
> MacOSX-dev mailing list
> <email_removed>
> http://www.omnigroup.com/mailman/listinfo/macosx-dev
>
| 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

