Search code examples
c++warningssdlrgblibpng

libpng warning: iCCP: known incorrect sRGB profile


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

libpng warning: iCCP: known incorrect sRGB profile

Why does this warning appear? What should I do to solve this problem?


Solution

  • Some applications treat warnings as errors; if you are using such an application, you do have to remove the chunk. You can do that with any variety of PNG editors, like ImageMagick.

    With Windows CMD prompt, you will need to cd (change directory) into the folder with the images you want to focus on before you can use the commands listed below.

    Libpng-1.6 is more stringent about checking ICC profiles than previous versions; you can ignore the warning. To get rid of it, remove the iCCP chunk from the PNG image.

    convert in.png out.png
    

    To remove the invalid iCCP chunk from all of the PNG files in a folder (directory), you can use mogrify from ImageMagick:

    mogrify *.png
    

    Or for Windows (if ImageMagick is on path):

    magick.exe mogrify *.png
    

    This requires that your ImageMagick was built with libpng16. You can easily check it by running:

    convert -list format | grep PNG
    

    If you'd like to find out which files need to be fixed instead of blindly processing all of them, you can run

    pngcrush -n -q *.png
    

    where the -n means don't rewrite the files and -q means suppress most of the output except for warnings. Sorry, there's no option yet in pngcrush to suppress everything but the warnings.

    Note: You must have pngcrush installed.


    Binary Releases of ImageMagick are here


    For Android Projects (Android Studio) navigate into res folder.

    For example:

    C:\{your_project_folder}\app\src\main\res\drawable-hdpi\mogrify *.png