Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NeonKingKong

macrumors member
Original poster
Nov 14, 2008
69
7
Portland, OR
Hello. I have a program that works fine, except that the documents I end up saving are huge. I am only uploading pictures and they end up to be much more than the combined size of the pictures I am uploading. I know there are some tricks I could be doing with NSImage, but I'm stuck when I read the documentation. If somebody could direct me to the types of methods inside the NSImage documentation that would help me save NSImages in a small way, I would appreciate it very much.

Right now I am using the traditional unarchive/archive saving/load implementation by saving a single data object that archives everything else.

Thank you.
 
Easiest way is to use the NSImage method TIFFRepresentationUsingCompression:factor:

NSBitmapImageRep has more options and other formats with representationUsingType:properties: - but your NSImage's representations may not contain an NSBitmapImageRep. If it doesn't, you can lock/unlockFocus on your NSImage and use initWithFocusedViewRect: to create an NSBitmapImageRep from it.

More low level is CGImageDestination inside ImageIO, but I imagine NSBitmapImageRep should do what you want.

As for saving your image data with other data, you could try a plist (see NSPropertyListSerialization) and passing that off to some form of compression.
 
I simply created an object the receives the dropped data and, when asked, returns the NSImage. When it encodes, it encodes only the NSData that was originally received, not the NSImage. This way, the file will be no larger than the original files.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.