NSImage DPI 问题

moo*_*ots 4 cocoa objective-c dpi nsimage

谁能告诉我如何获得 NSImage 的真实宽度和高度?我注意到 DPI 高于 72 的图像的 NSImage.size 参数的宽度和高度不准确。

我在 Cocoadev 上看到了这个例子:

NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];

NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);
Run Code Online (Sandbox Code Playgroud)

然而 bestRepresentationForDevice 在 10.6 上已被弃用...我可以使用什么作为替代方法,文档没有提供不同的方法?

小智 5

从 NSImage 的 TIFF 表示构建 NSBitmapImageRep

NSBitmapImageRep* rep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
Run Code Online (Sandbox Code Playgroud)