Finder/Preview 显示的 NSImage 代码大小不同
我在我的应用程序中使用了几张图像(其中附有其中一张)。奇怪的是,真实图像尺寸(由取景器和预览显示)是 1200x701 像素。
当我从代码中访问图像时,其大小为 360x210px。到底是怎么回事?
我用来获取图像大小的代码:
NSImage *newImg = [[NSImage alloc] initWithContentsOfURL:
[NSURL URLFromPasteboard:[sender draggingPasteboard]]];
float h = [newImg size].height; //height is 210px - should be 701px
float w = [newImg size].width; //width is 320px - should be 1200px
newImg 的内容与已指向并加载的图像相同 - 无论如何我都将其显示在 NSImageView 中,所以我明白了。只是用-size
取的尺寸是错误的。
这是图像:
I have a couple of images that i use in my application(one of them is attached). The strange thing is that the real image size(shown by finder and preview) is 1200x701 px.
When I access image from the code and as for its size, I get 360x210px. What is going on?
Code I'm using to get the size of the image:
NSImage *newImg = [[NSImage alloc] initWithContentsOfURL:
[NSURL URLFromPasteboard:[sender draggingPasteboard]]];
float h = [newImg size].height; //height is 210px - should be 701px
float w = [newImg size].width; //width is 320px - should be 1200px
The content of the newImg is the same image that has been pointed and loaded - I display it in the NSImageView anyway so I see. Just the size taken with -size
is wrong.
This is the image:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信 -[NSImage size] 返回以点为单位的大小,而不是像素。这就是为什么 NSImageRep 同时具有 size 方法以及pixelsHigh 和pixelsWide 方法。您的图像显然不是 72 dpi 分辨率。
I believe that -[NSImage size] returns the size in points, not pixels. That's why NSImageRep has both a size method and pixelsHigh and pixelsWide methods. Your image is apparently not at a 72 dpi resolution.
NSImage 可以包含同一图像的多个表示形式,每个表示形式的大小不同。我将查看
NSImage
上的-representations
方法,然后查看数组中返回的每个NSImageRep
对象以查看它有什么。An
NSImage
can contain multiple representations of the same image, each at different sizes. I'd take a look at the-representations
method onNSImage
, and then take a look at eachNSImageRep
object returned in the array to see what all it has.