Are specific PNG compression types incompatible with macOS Cocoa apps?

南笙酒味 提交于 2019-12-21 17:44:10

问题


We’ve had a recent issue with some asset images, where the Retina @2x version was being used on non-Retina devices. The Retina and non-Retina versions of the assets exist. We’ve tracked the problem down to compression, so we’re able avoid it for now, but if anyone has additional insights, I’d love to hear them.

The icons on the left show how they’re rendering inside the running app. The Retina assets are being used on a non-Retina screen, so they’re being scaled down to 50%, which is causing some blurry edges.

The icons on the right are the original assets.

This is only happening to some assets. Most of the app is okay. We’ve been using ImageOptim to compress the PNGs used in the app. ImageOptim is using a variety of compression combinations for the assets. These are the common best results:

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

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

Given that the issue isn’t always easy to spot, and given I don’t know exactly what’s wrong, we’ve unfortunately decided to not compress our new PNGs used in Mac apps. This is a shame, because the space savings are good.

We’ve tried a few different Xcode project settings, including turning Combine High Resolution Artwork on and off.

I’d like some answers, but I am also posting here so there’s some information that may help others with this issue, even if I only have a partial solution.


Have you seen this issue before?

If you have seen it, do you have a solution?


回答1:


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

You need to set prefersColorMatch to NO. There are User Defined Runtime Attributes to do it without leaving Interface Builder. This will fix the issue.

How to set prefersColorMatch in Interface Builder




回答2:


More information about the bug can be found here:

OS X doesn't like mixed types of PNGs.

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

It looks like there is no solution, except to force the same color_type for the PNG pairs.



来源:https://stackoverflow.com/questions/45295643/are-specific-png-compression-types-incompatible-with-macos-cocoa-apps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!