• 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 a NSImage/NSImageView to file
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: saving a NSImage/NSImageView to file


  • Subject: Re: saving a NSImage/NSImageView to file
  • From: John Pannell <email@hidden>
  • Date: Sat, 12 Mar 2005 13:19:40 -0700

Hi James-

IIf you are starting with an NSImage, you need to make an NSBitmapImageRep, pull the desired representation from it (NSJPEGFileType, NSGIFFileTyep, NSPNGFileType), and save that data to disk...

myJPEGRep = [[NSBitmapImageRep alloc] initWithFocusedViewRect:[[[mySourceImage representations] objectAtIndex:0] rect]];
myJPEGData = [myJPEGRep representationUsingType:NSJPEGFileType properties:nil];
[myJPEGData writeToFile:myJPEGLocation atomically:YES];


Note that in the code I copied this from, mySourceImage was something I created in code and then drew into ( via compositeToPoint ), so I knew that the representation at index 0 was the one I was interested in (it was an NSCachedImageRep). If such isn't the case for you, you could iterate through [mySourceImage representations] and fish out a rep that would work. I would think that, since you are drawing/editing, you would be after an NSCachedImageRep.

Hope this helps!

John


On Mar 12, 2005, at 11:47 AM, James Housley wrote:

I would think this is simple but I haven't been able get it to work, or find any good pointers after searching. Basically I want to load an image, (GIF, JPG or PNG); do some basic editing and save to a file. I would like to beable to save to (GIF, JPG or PNG), but if I have to limit to saving to the same format as it was loaded as that is okay for starters. If I load a PNG and then get NSBitmapImageRep of the image I can save it to a PNG and it looks right. Saving to GIF or JPG gives a black background. Loading a JPG fails on NSBitmapImageRep, I get a NSCachedImageRep.

Do I need to always go through a TIFFimageRep?

I would appreciate any pointers to a good tutorial or some simple sample code.

Thanks,
Jim

--

/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
email@hidden http://www.FreeBSD.org The Power to Serve
email@hidden http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup. _______________________________________________
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
 _______________________________________________
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

References: 
 >saving a NSImage/NSImageView to file (From: James Housley <email@hidden>)

  • Prev by Date: Re: Trying to understand "real memory" usage
  • Next by Date: Crash Log
  • Previous by thread: saving a NSImage/NSImageView to file
  • Next by thread: Crash Log
  • Index(es):
    • Date
    • Thread