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

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


  • Subject: Re: Saving an NSView to a file as an image.
  • From: Heinrich Giesen <email@hidden>
  • Date: Sun, 30 Apr 2006 17:54:24 +0200


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: This email sent to email@hidden
  • Prev by Date: Re: Creating alias to app for PDFService
  • Next by Date: Re: Distributed objects: Code required on both sides?
  • Previous by thread: Saving an NSView to a file as an image.
  • Next by thread: Creating alias to app for PDFService
  • Index(es):
    • Date
    • Thread