NSImage DPI 问题
谁能告诉我如何获得 NSImage 的真实宽度和高度?我注意到 DPI 高于 72 的图像的 NSImage.size 参数的宽度和高度不准确。
我在 Cocoadev 上看到了这个例子:
NSBitmapImageRep *rep = [image bestRepresentationForDevice: nil];
NSSize pixelSize = NSMakeSize([rep pixelsWide],[rep pixelsHigh]);
然而 bestRepresentationForDevice 在 10.6 上已被弃用...我可以使用什么作为替代方法,文档没有提供不同的方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 NSImage 的 TIFF 表示构建 NSBitmapImageRep
Build your NSBitmapImageRep from the TIFF representation of the NSImage
迭代图像的表示,寻找具有最大 -size 的图像。如果您提供一个非常大的矩形,则调用 -bestRepresentationForRect:context:hints: 应该会为您完成此操作。
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.