Saving an NSView to a file as an image.
Saving an NSView to a file as an image.
- Subject: Saving an NSView to a file as an image.
- From: Robert Tillyard <email@hidden>
- Date: Sun, 30 Apr 2006 11:19:59 +0100
I have an NSView that I want to be able to export via an NSSavePanel.
I can get my view into an NSImage with:
// Get the data into a bitmap.
[self lockFocus];
rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[self
bounds]];
[self unlockFocus];
// Make an NSImage from our bitmap.
image = [[[NSImage alloc] initWithSize:[rep size]] autorelease];
[image addRepresentation:rep];
// Convert to TIFF, we'd like to support other file types as well.
data = [image TIFFRepresentation];
However, I want to user to be able to use an NSSavePanel to save as a
JPG, BMP or whatever else they want the image to be. NSImage does
have a:
+ (NSArray *)imageFileTypes
Which I guess you can supply to NSSavePanel to list the types of file
that it can export but how do you handle the NSSavePanel and the
return, to write the image in the correct format?
Thanks, regards, Rob.
_______________________________________________
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