libpng warning: iCCP: known incorrect sRGB profile

2019-01-04 17:40发布

I'm trying to load a PNG file using SDL but the program doesn't work and this error appears in the console

"libpng warning: iCCP: known incorrect sRGB profile"

Why this warning appears? what should I do to solve this problem?

11条回答
smile是对你的礼貌
2楼-- · 2019-01-04 17:50

Here is a ridiculously brute force answer:

I modified the gradlew script. Here is my new exec command at the end of the file in the

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" **| grep -v "libpng warning:"**
查看更多
神经病院院长
3楼-- · 2019-01-04 17:55

You can also just fix this in photoshop... I've got CC2015 but I'm sure this is the same for all versions.

  1. Open your .png file.
  2. File -> Save As and in the dialog that opens up uncheck "ICC Profile: sRGB IEC61966-2.1"
  3. Uncheck "As a Copy".
  4. Courageously save over your original .png.
  5. Move on with your life knowing that you've removed just that little bit of evil from the world.
查看更多
劳资没心,怎么记你
4楼-- · 2019-01-04 17:55

Thanks to the fantastic answer from Glenn, I used ImageMagik's "mogrify *.png" functionality. However, I had images buried in sub-folders, so I used this simple Python script to apply this to all images in all sub-folders and thought it might help others:

import os
import subprocess

def system_call(args, cwd="."):
    print("Running '{}' in '{}'".format(str(args), cwd))
    subprocess.call(args, cwd=cwd)
    pass

def fix_image_files(root=os.curdir):
    for path, dirs, files in os.walk(os.path.abspath(root)):
        # sys.stdout.write('.')
        for dir in dirs:
            system_call("mogrify *.png", "{}".format(os.path.join(path, dir)))


fix_image_files(os.curdir)
查看更多
爱情/是我丢掉的垃圾
5楼-- · 2019-01-04 17:57

Use pngcrush to remove the incorrect sRGB profile from the png file:

pngcrush -ow -rem allb -reduce file.png
  • -ow will overwrite the input file
  • -rem allb will remove all ancillary chunks except tRNS and gAMA
  • -reduce does lossless color-type or bit-depth reduction

In the console output you should see Removed the sRGB chunk., and possibly more messages about chunk removals. You will end up with a smaller, optimized png file. As the command will overwrite the original file, make sure to create a backup or use version control.

查看更多
家丑人穷心不美
6楼-- · 2019-01-04 17:58

There is an easier way to fix this issue with Mac OS with Homebrew:

-> install homebrew if it is not installed yet
$brew install libpng
$pngfix --strip=color --out=file2.png file.png

or to do it with every file in the current directory:

mkdir tmp; for f in ./*.png; do pngfix --strip=color --out=tmp/"$f" "$f"; done

It will create a fixed copy for each png file in the current directory and put it in the the tmp subdirectory. After that, if everything is OK, you just need to override the original files.

Another tip is to use the Keynote and Preview applications to create the icons. I draw them using Keynote, in the size of about 120x120 pixels, over a slide with a white background (the option to make polygons editable is great!). Before exporting to Preview, I draw a rectangle around the icon (without any fill or shadow, just the outline, with the size of about 135x135) and copy everything to the clipboard. After that, you just need to open it with the Preview tool using "New from Clipboard", select a 128x128 pixels area around the icon, copy, use "New from Clipboard" again, and export it to PNG. You won't need to run the pngfix tool.

查看更多
戒情不戒烟
7楼-- · 2019-01-04 18:05

Using IrfanView image viewer in Windows, I simply resaved the PNG image and that corrected the problem.

查看更多
登录 后发表回答