Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSImage DPI Question

Can anyone tell me how I can get the true width and height of an NSImage? I have noticed that images that are a higher DPI than 72 come through with inaccurate width and height with the NSImage.size parameters.

I saw this example on Cocoadev:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];

NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);

However bestRepresentationForDevice is deprecated on 10.6... what can I use as an alternative, the documentation doesn't offer a different method?

like image 913
mootymoots Avatar asked Oct 17 '25 14:10

mootymoots


2 Answers

Build your NSBitmapImageRep from the TIFF representation of the NSImage

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
like image 151
Comrade Yeti Avatar answered Oct 21 '25 16:10

Comrade Yeti


Iterate through the image's representation looking for the one with the largest -size. Calling -bestRepresentationForRect:context:hints: should do this for you if you feed an extremely large rectangle.

like image 44
Mike Abdullah Avatar answered Oct 21 '25 15:10

Mike Abdullah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!