我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
当前回答
在Windows中使用IrfanView图像查看器,我简单地重新保存了PNG图像,这纠正了问题。
其他回答
在Windows中使用IrfanView图像查看器,我简单地重新保存了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.
使用pngcrush从png文件中删除不正确的sRGB配置文件:
pngcrush -ow -rem allb -reduce file.png
-ow将覆盖输入文件 -rem allb将删除除tRNS和gAMA之外的所有辅助块 -reduce用于无损颜色类型或位深度缩减
在控制台输出中,您应该看到Removed the sRGB块,可能还有更多关于块移除的消息。你将得到一个更小的、优化过的PNG文件。由于该命令将覆盖原始文件,请确保创建备份或使用版本控制。
一些建议的答案使用pngcrush和-rem allb选项,文档说这就像“用电锯做手术”。该选项删除了许多块。为了防止“iCCP:已知错误的sRGB配置文件”警告,删除iCCP块就足够了,如下所示:
pngcrush -ow -rem iCCP filename.png
PHP开发者使用imagecreatefromng函数时遇到的问题
您可以尝试使用@取消警告
$img = @imagecreatefrompng($file);