NSImage size?

Discussion in 'Mac Programming' started by spider87, Mar 3, 2011.

  1. spider87 macrumors newbie

    Mar 3, 2011
    I have a 16000x8000 image and I'm trying to load it into an NSImage. When I load it in and report the width and height to myself it tells me it's 2880x1440... What would be causing this? Here's the code I'm using to import:

    -(void) awakeFromNib
         bigImage = [[NSImage alloc] initWithContentsOfFile:@"/myfile.tif"];
         [bigImage setCacheMode:NSImageCacheNever];
         [bigImage setDataRetained:YES];
         [imgView setImage:bigImage];
    then when I do
    NSLog(@"W %f",bigImage.size.width); NSLog(@"H %f",bigImage.size.height);
    It outputs:

    W 2880.000000
    H 1440.000000

    Why? I have verified that the image is 16000x8000 and for some odd reason when you just open the program and then save the image through it without making any transformations (flip/rotate/etc) (it's an image transforming program) it will output it as the correct 16000x8000.

    I think the reason for the above note is that in the transformation functions we exchange dimensions for the images so we have:

    NSImage *tmpImage;
    NSSize dimensions = [bigImage size];
    tmpImage= [[NSImage alloc] initWithSize:dimensions];
    And, of course, as I said the 'bigImage' size shows as 2880x1440..

    Anyone have any ideas?

  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    An NSImage's size property takes resolution (PPI) into account.

    If you want dimensions in pixels, then you need an NSImageRep and its pixelsHigh and pixelsWide methods.
  3. spider87 thread starter macrumors newbie

    Mar 3, 2011
    Thanks for the response. While waiting I forced a size by creating a new size of 16000x8000 and set the size of the bigImage to that and now does its function and saves properly. HOWEVER, we are still having issues with dpi it's saving as 72dpi instead of 400dpi. Will adapting to NSImageRep fix that as well?
  4. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Read the class reference doc for NSImageRep.

    Then look at the basic arithmetic:
    16000 * 72 / 400 = 2880

Share This Page