NSImage information

  • I have never used NSImage very much, however I've spent the last hour
    or so going over the header and the info I could find on the
    developer site and I'm not seeing my answer, so I am hoping some one
    might know.
    Using NSImage and NSImageRep it appears to be possible to import
    JPG,PNG and TIFF images (among many others.) Thats pretty clear and
    obvious. However I have been asked to create a program for a
    photographer that will take tiff files and allow her to resize them
    (also seems rather clear in the header.) then save them as maximum
    quality jpeg files. I did not see a Jpeg image rep header... I hope
    it wasn't staring me in the face. Do the Appkit NSImage and various
    image reps allow for the conversion from one format to the next or am
    I going to have to license a library from some where?

    Thanks
    April.
  • On Sep 21, 2007, at 12:42 AM, Development wrote:

    > I have never used NSImage very much, however I've spent the last
    > hour or so going over the header and the info I could find on the
    > developer site and I'm not seeing my answer, so I am hoping some one
    > might know.
    > Using NSImage and NSImageRep it appears to be possible to import
    > JPG,PNG and TIFF images (among many others.) Thats pretty clear and
    > obvious. However I have been asked to create a program for a
    > photographer that will take tiff files and allow her to resize them
    > (also seems rather clear in the header.) then save them as maximum
    > quality jpeg files. I did not see a Jpeg image rep header... I hope
    > it wasn't staring me in the face. Do the Appkit NSImage and various
    > image reps allow for the conversion from one format to the next or
    > am I going to have to license a library from some where?
    >

    You need to manipulate the underlying NSBitmapImageRep (typically by
    asking the NSImage for the best representation)

    then use the method

    - (NSData *)representationUsingType:(NSBitmapImageFileType)storageType
    properties:(NSDictionary *)properties

    documented here

    http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Cla
    sses/NSBitmapImageRep_Class/index.html#/

    /apple_ref/doc/uid/TP40004009
  • Thank you very much for your reply... Hmmm, I searched NSImageRep and
    NSImage and did not think to search the bitmap I just assumed it was
    a reference to the windows bmp file type. I see very clearly now that
    it would return the data I want based on what I tell it.

    The other question I had that I do not think my email clearly stated
    looking back at it, was the quality issue for the jpeg. Now as I am
    looking at the bitimagerep there is a key for compression factor. My
    intuition tells me that if I set this number to 1.0 I will get the
    best quality image and if I set it to 0.0 I'll get a very small very
    fast very ugly image. Is this correct or do I still need to keep
    reading?

    Thanks again
    April.
  • Depending on what your photographer's needs are, you might find the
    SIPS facility

    <http://developer.apple.com/documentation/Darwin/Reference/ManPages/
    man1/sips.1.html
    >

    or an Automator workflow more straightforward.

    _murat

    On Sep 20, 2007, at 10:07 PM, Development wrote:

    > Thank you very much for your reply... Hmmm, I searched NSImageRep
    > and NSImage and did not think to search the bitmap I just assumed
    > it was a reference to the windows bmp file type. I see very clearly
    > now that it would return the data I want based on what I tell it.
    >
    > The other question I had that I do not think my email clearly
    > stated looking back at it, was the quality issue for the jpeg. Now
    > as I am looking at the bitimagerep there is a key for compression
    > factor. My intuition tells me that if I set this number to 1.0 I
    > will get the best quality image and if I set it to 0.0 I'll get a
    > very small very fast very ugly image. Is this correct or do I still
    > need to keep reading?
  • A factor of 1.0 gives you maximum compression, while
    0.0 gives you maximum quality. This is an NSImage
    category I wrote.

    - (NSData
    *)JPEGDataWithCompressionFactor:(float)factor
    {
    [self lockFocus];

    NSBitmapImageRep  *bmRep = [[NSBitmapImageRep alloc]
    initWithFocusedViewRect:[self bounds]];

    [self unlockFocus];

    NSNumber  *factorNumber = [NSNumber
    numberWithFloat:factor];
    NSDictionary  *props = [NSDictionary
    dictionaryWithObject:factorNumber
    forKey:NSImageCompressionFactor];
    NSData    *jpgData = [bmRep
    representationUsingType:NSJPEGFileType
    properties:props];

    [bmRep release];


    return jpgData;
    }

    Hope this helps.

    --- Development <development...> wrote:

    > Thank you very much for your reply... Hmmm, I
    > searched NSImageRep and
    > NSImage and did not think to search the bitmap I
    > just assumed it was
    > a reference to the windows bmp file type. I see very
    > clearly now that
    > it would return the data I want based on what I tell
    > it.
    >
    > The other question I had that I do not think my
    > email clearly stated
    > looking back at it, was the quality issue for the
    > jpeg. Now as I am
    > looking at the bitimagerep there is a key for
    > compression factor. My
    > intuition tells me that if I set this number to 1.0
    > I will get the
    > best quality image and if I set it to 0.0 I'll get a
    > very small very
    > fast very ugly image. Is this correct or do I still
    > need to keep
    > reading?
    >
    >
    > Thanks again
    > April.
    >


    ____________________________________________________________________________________
    Moody friends. Drama queens. Your life? Nope! - their life, your story. Play Sims Stories at Yahoo! Games.
    http://sims.yahoo.com/
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today