Are specific PNG compression types incompatible with macOS Cocoa applications?

Weve had a recent problem with some resource images where the Retina @2x version was used on devices other than Retina. There are versions of Retina and non-Retina. Weve tracked the problem to compression, so now I managed to avoid it, but if anyone has additional ideas, I love listening to them.

The icons on the left show how to render them inside the running application. Retina assets are used on the screen without a retina, so they are reduced to 50%, which causes some blurry edges.

The icons on the right are the original assets.

PNG compression causing retina-free problems

This only happens with some assets. Most apps are fine. Weve used ImageOptim to compress the PNGs used in the application. ImageOptim uses various compression combinations for assets. These are the best results:

  • PNGOUT
  • PNGOUT+AdvPNG
  • PNGOUT+Zopfli
  • AdvPNG+Zopfli

Assets that have problems seem to be using PNGOUT+Zopfli , but not all assets with PNGOUT+Zopfli are bad. I am not 100% sure with this diagnosis.

Given that the problem is not always easy to detect, and given that I do not know exactly what happened, we unfortunately decided not to compress our new PNGs used in Mac applications. This is a shame because saving space is good.

Weve tried several different settings for the Xcode project, including turning Combine High Resolution Artwork on and off.

Combine High Resolution Work in Xcode

Id like some answers, but I also post here, so that you have information that can help others with this problem, even if I only have a partial solution.


Have you seen this problem before?

If you saw this, do you have a solution?

+4
source share
2 answers

By default, NSImage are selected using type and color resolution [ 1 ]. In the case of PNG files, there are situations when a more general color type gives a smaller file. This is what causes mixed types of colors between representations.

You need to set prefersColorMatch to NO . For this, custom Runtime attributes are used without leaving the Builder interface. This will fix the problem.

How to install prefersColorMatch in Interface Builder

+1
source

More information about the error can be found here:

OS X does not like mixed PNG types.

Retina version of an image always used to display non-retina

There seems to be no solution, except that for PNG pairs the same color_type .

+1
source

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


All Articles