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;