NSImage size?

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

  1. spider87 macrumors newbie

    Joined:
    Mar 3, 2011
    #1
    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:

    Code:
    -(void) awakeFromNib
    {
         bigImage = [[NSImage alloc] initWithContentsOfFile:@"/myfile.tif"];
         [bigImage setCacheMode:NSImageCacheNever];
         [bigImage setDataRetained:YES];
         [imgView setImage:bigImage];
         NSRunAlertPanel(@"DONE",@"DONE",@"OK",nil,nil);
    }
    
    then when I do
    Code:
    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:

    Code:
    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?

    Thanks,
    Alex
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    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

    Joined:
    Mar 3, 2011
    #3
    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

    Joined:
    Aug 9, 2009
    #4
    Read the class reference doc for NSImageRep.

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

Share This Page