Finder/Preview 显示的 NSImage 代码大小不同

发布于 2024-09-04 08:42:42 字数 686 浏览 5 评论 0原文

我在我的应用程序中使用了几张图像(其中附有其中一张)。奇怪的是,真实图像尺寸(由取景器和预览显示)是 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取的尺寸是错误的。

这是图像:

替代文本 http://www.tomaszkrasnyk.yoyo.pl/image.jpg

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:

alt text http://www.tomaszkrasnyk.yoyo.pl/image.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不气馁 2024-09-11 08:42:42

我相信 -[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.

唱一曲作罢 2024-09-11 08:42:42
NSImageRep *imgRep = [NSImageRep imageRepWithContentsOfFile:imagePath];
int imageWidth = (int)[imgRep pixelsWide];
int imageHeight = (int)[imgRep pixelsHigh];
imgRep = nil;

NSLog(@"original image width: %d",imageWidth);
NSLog(@"original image height: %d",imageHeight);
NSImageRep *imgRep = [NSImageRep imageRepWithContentsOfFile:imagePath];
int imageWidth = (int)[imgRep pixelsWide];
int imageHeight = (int)[imgRep pixelsHigh];
imgRep = nil;

NSLog(@"original image width: %d",imageWidth);
NSLog(@"original image height: %d",imageHeight);
猫烠⑼条掵仅有一顆心 2024-09-11 08:42:42

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 on NSImage, and then take a look at each NSImageRep object returned in the array to see what all it has.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文