Mailing Lists: Apple Mailing Lists

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

Re: Saving an NSView to a file as an image.




On 30.04.2006, at 16:45, Robert Tillyard wrote:

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];

So far so good.

// Make an NSImage from our bitmap.

Here you run into a selfmade trap. Why do you create an NSImage instance?
You don't need it. You can create the TIFF data directly from the rep:


data = [rep TIFFRepresentation];
// (see the docs for NSBitmapImageRep)
or better
data = [rep TIFFRepresentationUsingCompression: compression factor:aFactor];


// we'd like to support other file types as well.

no problem with a rep:

data = [rep representationUsingType:(NSBitmapImageFileType) storageType
properties:(NSDictionary *)properties];


from the docs:
An enum constant specifying a file type for bitmap images. It can be NSBMPFileType, NSGIFFileType, NSJPEGFileType, NSPNGFileType, or NSTIFFFileType.


+ (NSArray *)imageFileTypes

forget it, it has to do with the input of files only.

how do you handle the NSSavePanel and the
return, to write the image in the correct format?

Use an accessoryView which may look like the one of the Preview.app.


-- Heinrich Giesen email@hidden


_______________________________________________ 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.