Saving as JPEG
Saving as JPEG
- Subject: Saving as JPEG
- From: Ted Lowery <email@hidden>
- Date: Thu, 16 Jan 2003 21:34:26 -0500
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.