Solve Qt: libpng warning: iCCP: known incorrect sRGB profile

Solve Qt: libpng warning: iCCP: known incorrect sRGB profile

libpng is more stringent about checking ICC profiles than previous versions. In Qt, if you use certain formats of PNG images, you may get a warning ‘libpng warning: iCCP: known incorrect sRGB profile’, though this will not affect the compilation.


Why this happens?

This warning is mainly related to the format of the PNG image. In fact, to solve this warning, we just need to convert the image to a correct profile. There are many ways to solve this in both Windows and Linux.

Windows

Method 1: ImageMagick

We use ImageMagick to convert the image: ImageMagick Official

  • Download the corresponding compressed package according to the platform (such as Windows x64)
  • Unzip the downloaded compressed package to anywhere you want, we suppose your target path is $PATH.
  • Create a new .bat file in the PNG folder, for example convert.bat.
  • Edit the content of convert.bat:
@echo off
echo ImageMagick is fixing libpng warning
set fn = $PATH\convert.exe
for /f "tokens=*" %%i in ('dir/s/b *.png') do "%fn%" "%%i" -strip "%%i"
pause
  • Save the convert.bat, then double click to run it.

Method 2: Photoshop

  • Open the image with Photoshop.
  • Click Edit on the tool bar.
  • Change the image profile to “Adobe RGB (1998)”.

Method 3: QImage

QImage img;
img.load("1.png");
img.save("1.png");

Linux

Method 1: convert

It’s the easiest way to solve the warning in Linux:

$ convert input.png output.png

If you don’t have a convert command, just install it, it is included in ImageMagick:

$ sudo apt-get install imagemagick
$ convert -version

convert also has many more excellent functions, you can resize your image like this:

$ convert -resize 1024x1024 input.png output.png

Rotate the image:

$ convert -rotate 270 input.png output.png    #clockwise rotate 270 degrees

Even add characters:

$ convert -fill COLOR -pointsize SIZE -font FONT -draw 'text X,Y "Hello, World!"' input.png output.png 

And many more…

Method 2: QImage()

QImage img;
img.load("1.png");
img.save("1.png");

© 2020-2021. All rights reserved.