Retina version of the image always used on the display without a retina

In a Cocoa application, I have 16x16 and 32x32 @2x version of the image: smallenter image description here . When an image is displayed in NSImageView, Mac OS X always selects a higher resolution version (i.e., Reduces the @2x image on non-retina displays instead of using 1: 1 version).

wrong image
(IB on the left = ok, the application on the right = downscaled mess works)

Of course, I have both images added to the project (like image.png and image@2x.png ).

If I remove the @2x image from the application package, then OS X will display a lower resolution image.

The error occurs regardless of whether Xcode (4.6.2) combines their .tiff or not (and I checked that the combined .tiff contains both images).

Oddly enough, this only happens with this particular image. Other 1x / 2x images in the same project are displayed correctly, corresponding DPI screen.

How is this possible ?! Should the images meet some special criteria other than the size and pattern of the file name?

+4
source share
2 answers

This is the NSImage s prefersColorMatch [1] property:

The default value is YES. Color matching and resolution may affect image selection.

In the Runtime attributes of the Runtime in Interface Builder [2], you can set NO .

[1] https://developer.apple.com/documentation/appkit/nsimage/1520010-preferscolormatch

[2] Are specific PNG compression types incompatible with macOS Cocoa applications?

+2
source

Mystery solved: OS X does not like mixed PNG types.

 $ file *.png image.png: PNG image data, 16 x 16, 8-bit gray+alpha, non-interlaced image@2x.png : PNG image data, 32 x 32, 8-bit colormap, non-interlaced 

if both files are forced to use the same color mode (i.e., both gray and both below deck), then OS X displays images correctly.

+5
source

Source: https://habr.com/ru/post/1481847/


All Articles