• 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
Saving an NSView to a file as an image.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Prev by Date: NSOpenPanel setCanChooseDirectories behavior
  • Next by Date: Mailing List for Cocoa Newbies / Absolute Beginners
  • Previous by thread: Re: NSOpenPanel setCanChooseDirectories behavior
  • Next by thread: Re: Saving an NSView to a file as an image.
  • Index(es):
    • Date
    • Thread