始终在非视网膜显示器上使用的图像的视网膜版本 [英] Retina version of an image always used on non-retina display
问题描述
在可可应用程序中,我有图像的16x16和32x32 @ 2x
版本: 。当图像在NSImageView Mac OS X中显示时,总是选择较高分辨率的版本(即,在非视网膜显示器上缩小 @ 2x
图像的尺寸,而不是使用1:1版本)。
(左边的IB =好,右边运行的应用程序=缩小的混乱)
将两个图像都添加到了项目中(分别为 image.png
和 image@2x.png
)。
如果我从应用程序捆绑包中删除了 @ 2x
图像,则OS X将显示较低分辨率的图像。 / p>
无论Xcode(4.6.2)是否将它们组合成.tiff(并且我已经检查了组合后的.tiff包含两个图像),都会发生该错误。 / p>
奇怪的是,这种情况仅在此特定图像上发生。在同一项目中显示的其他1x / 2x图像与屏幕DPI正确匹配。
那怎么可能?!图像是否必须满足大小和文件名模式以外的其他特殊条件?
事实证明是 NSImage
的 prefersColorMatch
属性[1]:
默认值为YES。颜色匹配和分辨率匹配都可能影响图像表示的选择。
可以将其设置为接口构建器[2]中用户定义的运行时属性中没有。
[1] https://developer.apple.com/documentation/appkit/nsimage/1520010-preferscolormatch
[2] 特定的PNG压缩类型是否与macOS Cocoa应用程序不兼容?
In Cocoa application I've got 16x16 and 32x32 @2x
version of an image: . When the image is displayed in NSImageView Mac OS X always picks higher-resolution version (i.e. downscales the @2x
image on non-retina displays instead of using the 1:1 version).
(IB on the left = good, running app on the right = downscaled mess)
Of course I've got both images added to the project (as image.png
and image@2x.png
).
If I delete the @2x
image from app bundle then OS X will display the lower-resolution image.
The bug happens regardless whether Xcode (4.6.2) combines them into a .tiff or not (and I've checked that the combined .tiff contains both images).
Oddly this happens only with this particular image. Other 1x/2x images in the same project are displayed correctly matching screen DPI.
How is that possible?! Do images have to meet some special criteria other than size and filename pattern?
It turns out to be the NSImage
’s prefersColorMatch
property [1]:
The default value is YES. Both color matching and resolution matching may influence the choice of an image representation.
It is possible to set to NO
in User Defined Runtime Attributes in Interface Builder [2].
[1] https://developer.apple.com/documentation/appkit/nsimage/1520010-preferscolormatch
[2] Are specific PNG compression types incompatible with macOS Cocoa apps?
这篇关于始终在非视网膜显示器上使用的图像的视网膜版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!