Search code examples
objective-ccocoadpinsimage

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?


Solution

  • Build your NSBitmapImageRep from the TIFF representation of the NSImage

    NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];