Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Saving an NSView to a file as an image.



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.