faqts : Computers : Programming : Application Frameworks : Macintosh : Cocoa

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

7 of 9 people (78%) answered Yes
Recently 7 of 9 people (78%) answered Yes

Entry

How do I find out the resolution of an NSImage?

Apr 30th, 2002 14:19
Christopher Holland, John C. Randolph


The resolution isn't an attribute of the image, it's an attribute of an
NSImageRep.
So, in the case where an NSImage contains one imageRep, (say, an
NSBitmapImageRep), you can get the resolution like this:
  float hres, vres;
  NSImage *myImage = [NSImage imageWithContentsOfFile:@"/path/to/my.tiff"];
  NSSize imageSize = [myImage size];
  NSImageRep *myRep = [[myImage representations] objectAtIndex:0]; //Should only be one..
  // note that these aren't necessarily identical.
  hres = [myRep pixelsWide]/imageSize.width;
  vres = [myRep pixelsWide]/imageSize.height;