Re: Saving an NSImage to an image file
Re: Saving an NSImage to an image file
- Subject: Re: Saving an NSImage to an image file
- From: Ron Fleckner <email@hidden>
- Date: Mon, 5 Jun 2006 09:19:15 +1000
From: Graham <email@hidden>
I can find a couple of sample pieces to do this, but they are part of
something more complex and I cannot determine what I need.
So how do I save an NSImage instance (obtained from an NSURL) into a
file, .tif or jpeg or whatever? Assume I already have a file path for
the file.
This works for me:
- (IBAction)saveImage:(id)sender
{
NSData *tiffData = [[myView fileIcon] TIFFRepresentation];
int runResult;
NSSavePanel *sp = [NSSavePanel savePanel];
[sp setCanSelectHiddenExtension:YES];
[sp setRequiredFileType:@"tif"];
runResult = [sp runModalForDirectory:nil file:nil];
if (runResult == NSOKButton) {
if (![tiffData writeToFile:[sp filename] atomically:YES])
NSLog(@"didn't work!");
}
}
fileIcon is an NSImage instance. I don't exactly remember, but I
think I may have copied most of this from the docs.
HTH
Ron Fleckner
_______________________________________________
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