我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
当前回答
一些建议的答案使用pngcrush和-rem allb选项,文档说这就像“用电锯做手术”。该选项删除了许多块。为了防止“iCCP:已知错误的sRGB配置文件”警告,删除iCCP块就足够了,如下所示:
pngcrush -ow -rem iCCP filename.png
其他回答
扩展friederbluemle解决方案,下载pngcrush,然后如果你在多个png文件上运行它,就像这样使用代码
path =r"C:\\project\\project\\images" # path to all .png images
import os
png_files =[]
for dirpath, subdirs, files in os.walk(path):
for x in files:
if x.endswith(".png"):
png_files.append(os.path.join(dirpath, x))
file =r'C:\\Users\\user\\Downloads\\pngcrush_1_8_9_w64.exe' #pngcrush file
for name in png_files:
cmd = r'{} -ow -rem allb -reduce {}'.format(file,name)
os.system(cmd)
这里所有与项目相关的PNG文件都在一个文件夹中。
感谢Glenn的精彩回答,我使用了ImageMagik的“mogrify *.png”功能。然而,我的子文件夹中隐藏了图像,所以我使用了这个简单的Python脚本来应用于所有子文件夹中的所有图像,并认为它可能会帮助到其他人:
import os
import subprocess
def system_call(args, cwd="."):
print("Running '{}' in '{}'".format(str(args), cwd))
subprocess.call(args, cwd=cwd)
pass
def fix_image_files(root=os.curdir):
for path, dirs, files in os.walk(os.path.abspath(root)):
# sys.stdout.write('.')
for dir in dirs:
system_call("mogrify *.png", "{}".format(os.path.join(path, dir)))
fix_image_files(os.curdir)
一些背景信息:
libpng 1.6+版本中的一些更改导致它发出警告或 甚至不能与原始HP/MS sRGB配置文件正确工作,领先 到以下stderr: libpng警告:iCCP:已知错误的sRGB 旧的配置文件使用D50白点,其中D65是标准的。 这个配置文件并不少见,虽然Adobe Photoshop正在使用 默认情况下,它没有嵌入到图像中。
(来源:https://wiki.archlinux.org/index.php/Libpng_errors)
Error detection in some chunks has improved; in particular the iCCP chunk reader now does pretty complete validation of the basic format. Some bad profiles that were previously accepted are now rejected, in particular the very old broken Microsoft/HP sRGB profile. The PNG spec requirement that only grayscale profiles may appear in images with color type 0 or 4 and that even if the image only contains gray pixels, only RGB profiles may appear in images with color type 2, 3, or 6, is now enforced. The sRGB chunk is allowed to appear in images with any color type.
(来源:https://forum.qt.io/topic/58638/solved-libpng-warning-iccp-known-incorrect-srgb-profile-drive-me-nuts/16)
在Windows中使用IrfanView图像查看器,我简单地重新保存了PNG图像,这纠正了问题。
一些建议的答案使用pngcrush和-rem allb选项,文档说这就像“用电锯做手术”。该选项删除了许多块。为了防止“iCCP:已知错误的sRGB配置文件”警告,删除iCCP块就足够了,如下所示:
pngcrush -ow -rem iCCP filename.png