I try to load a PNG image using SDL but the program doesn't run and I get this error in the console
libpng WARNING: iCCP: Known incorrect sRGB profile
Why does this warning appear? What should I do to resolve this issue?
P粉4810352322023-10-13 18:57:24
Remove incorrect sRGB profiles from png files using pngcrush
:
pngcrush -ow -rem allb -reduce file.png
-ow
will overwrite the input file-rem allb
will remove all auxiliary blocks except tRNS and gAMA-reduce
Perform lossless color type or bit depth reductionIn the console output you should see Removed the sRGB chunk
, and possibly more messages about chunk removal. You'll end up with a smaller, optimized PNG file. Since this command will overwrite the original file, make sure to create a backup or use version control.
P粉3005417982023-10-13 14:10:19
Some applications treat warnings as errors; if you are using such an application, you must remove this block. You can do this using any kind of PNG editor, such as ImageMagick.
Using Windows CMD prompt, you need to cd
(change directory) to the folder containing the images you want to focus on before you can use the commands listed below.
Libpng-1.6 has stricter checks for ICC profiles than previous versions; you can ignore the warning. To get rid of it, remove the iCCP block from the PNG image.
convert in.png out.png
To remove invalid iCCP blocks from all PNG files in a folder (directory), you can use mogrify
from ImageMagick:
mogrify *.png
This requires that your ImageMagick is built with libpng16. You can easily check it by running:
convert -list format | grep PNG
If you want to find out which files need to be repaired instead of blindly processing them all, you can run
pngcrush -n -q *.png
Where -n
means not to rewrite the file, -q
means to suppress most output except warnings. Sorry, there is no option yet in pngcrush to suppress everything except warnings.
Note: You must have pngcrush installed.
Binary versions of ImageMagick are located here
For Android projects (Android Studio), navigate to the res
folder.
For example:
C:\{your_project_folder}\app\src\main\res\drawable-hdpi\mogrify *.png