Dealing With, Saving NSImages...

Discussion in 'Mac Programming' started by NeonKingKong, May 6, 2010.

  1. NeonKingKong macrumors member

    NeonKingKong

    Joined:
    Nov 14, 2008
    Location:
    Portland, OR
    #1
    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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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.
     
  3. NeonKingKong thread starter macrumors member

    NeonKingKong

    Joined:
    Nov 14, 2008
    Location:
    Portland, OR
    #3
    Thank you very much for your reply. I will look into this.
     
  4. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #4
    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.
     

Share This Page