• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Saving an NSImage to an image file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: Re: Saving an NSImage to an image file
  • Next by Date: [SOLVED]Re: NSControl and NSCell
  • Previous by thread: Re: Saving an NSImage to an image file
  • Next by thread: How can a browser's cell determine which matrix it is in?
  • Index(es):
    • Date
    • Thread