Re: Saving as JPEG
Re: Saving as JPEG
- Subject: Re: Saving as JPEG
- From: Marco Binder <email@hidden>
- Date: Fri, 17 Jan 2003 10:17:19 +0100
NSCachedImageRep doesnt understand the representationOfType message (as
the docs will tell you). Thats why you called this function on the
NSBitmapImageRep class! So you have to make your image into an
NSBitmapImageRep obviously.
1) get the TIFF data of the image and use it to initialize a
NSBitmapImageRep
2) call representationOfType: on this NSBitmapImageRep and pass
NSJPEGFileType (and optionally a properties dictionary to set the
compression factor)
Marco
Am Freitag, 17.01.03 um 03:34 Uhr schrieb Ted Lowery:
Hi all-
I'm trying to save an image as a JPEG file. I thought it was as simple
as creating an NSImage, grabbing the bitmap data using JPEG
representation, and writing the file. Here is my code:
- (IBAction)saveDocumentAsJpeg:(id)sender { debug;
// create an NSImage the same size as the document window
NSSize size;
size.width = NSWidth([[drawWindowController window] frame]);
size.height = NSHeight([[drawWindowController window] frame]);
NSImage* image = [[NSImage alloc] initWithSize:size];
// draw the objects into the image
[image lockFocus];
NSEnumerator* e = [objects objectEnumerator];
QDObject* object;
while (object = [e nextObject])
[object draw];
[image unlockFocus];
// convert the data to a JPEG represenation
NSArray* representations = [image representations];
NSLog([representations description]);
NSData* bitmapData = [NSBitmapImageRep
representationOfImageRepsInArray:representations
usingType:NSJPEGFileType
properties:nil];
// save and cleanup
[bitmapData writeToFile:@"JpegImage.jpeg" atomically:YES];
[image release];
}
And here is the log:
2003-01-16 21:30:41.822 QDraw[20637] (
NSCachedImageRep 0x148d460 Size={734, 686}
ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=734x686 Alpha=YES
)
2003-01-16 21:30:41.822 QDraw[20637] *** -[NSCachedImageRep
representationUsingType:properties:]: selector not recognized
2003-01-16 21:30:41.826 QDraw[20637] *** -[NSCachedImageRep
representationUsingType:properties:]: selector not recognized
I guess I need to coerce my image to something other than an
NSCachedImageRep, but I am flying blind here. I can't seem to find any
documentation on how to do this on any of the usual sources.
Thanks for any help...
Cheers, Ted
_______________________________________________
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.
--
|\ /| E-Mail: email@hidden WWW: www.marco-binder.de
| \/ | Telefon: 07531 / 94 19 94 Fax: 07531 / 94 19 92
| |ARCO Snail-Mail: Banater Str. 3 - 78467 Konstanz
BINDER _____________________________________________________
_______________________________________________
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.