我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中

libpng警告:iCCP:已知错误的sRGB配置文件

为什么会出现这个警告?我该怎么解决这个问题呢?


当前回答

下面是一个荒谬粗暴的回答:

我修改了gradlew脚本。下面是我的新exec命令在文件的末尾

exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" **| grep -v "libpng warning:"**

其他回答

我在项目的根目录中运行了这两个命令,它已经修复了。

基本上是将“find”命令的输出重定向到一个文本文件,用作要处理的文件列表。然后你可以使用“@”标志将文本文件读入“mogrify”:

找到*.png -mtime -1 > list.txt Mogrify -resize 50% @list.txt

这将使用“find”来获取所有更新超过1天的*.png图像,并将它们打印到名为“list.txt”的文件中。然后“mogrify”读取该列表,处理图像,并用调整大小的版本覆盖原始图像。在不同的系统中,“find”的行为可能会有微小的差异,因此您必须检查手册页以了解确切的用法。

PHP开发者使用imagecreatefromng函数时遇到的问题

您可以尝试使用@取消警告

$img = @imagecreatefrompng($file);

一些应用程序将警告视为错误;如果您正在使用这样的应用程序,则必须删除该块。你可以使用任何PNG编辑器,比如ImageMagick。

在Windows CMD提示符下,在使用下面列出的命令之前,您需要将cd(改变目录)放入您想要聚焦的图像的文件夹中。

Libpng-1.6在检查ICC配置文件方面比以前的版本更加严格;您可以忽略该警告。要摆脱它,请从PNG图像中删除iCCP块。

convert in.png out.png

要从文件夹(目录)中的所有PNG文件中删除无效的iCCP块,您可以使用mogrify from ImageMagick:

mogrify *.png

这要求您的ImageMagick是用libpng16构建的。你可以通过运行:

convert -list format | grep PNG

如果您想找出哪些文件需要修复,而不是盲目地处理所有文件,您可以运行

pngcrush -n -q *.png

其中-n表示不重写文件,-q表示除警告外抑制大部分输出。对不起,在pngcrush中还没有选项来压制除警告之外的所有内容。

注意:必须安装pngcrush。


ImageMagick的二进制版本在这里


对于Android项目(Android Studio)导航到res文件夹。

例如:

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

一些建议的答案使用pngcrush和-rem allb选项,文档说这就像“用电锯做手术”。该选项删除了许多块。为了防止“iCCP:已知错误的sRGB配置文件”警告,删除iCCP块就足够了,如下所示:

pngcrush -ow -rem iCCP filename.png

在Mac OS和Homebrew上有一个更简单的方法来修复这个问题:

如果还没有安装,请安装自制软件

$brew install libpng
$pngfix --strip=color --out=file2.png file.png

或者对当前目录中的每个文件都这样做:

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

它将为当前目录中的每个png文件创建一个固定副本,并将其放在tmp子目录中。之后,如果一切正常,您只需要重写原始文件。

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.