我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
我试图使用SDL加载PNG图像,但程序不工作,这个错误出现在控制台中
libpng警告:iCCP:已知错误的sRGB配置文件
为什么会出现这个警告?我该怎么解决这个问题呢?
当前回答
感谢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)
其他回答
扩展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文件都在一个文件夹中。
使用pngcrush从png文件中删除不正确的sRGB配置文件:
pngcrush -ow -rem allb -reduce file.png
-ow将覆盖输入文件 -rem allb将删除除tRNS和gAMA之外的所有辅助块 -reduce用于无损颜色类型或位深度缩减
在控制台输出中,您应该看到Removed the sRGB块,可能还有更多关于块移除的消息。你将得到一个更小的、优化过的PNG文件。由于该命令将覆盖原始文件,请确保创建备份或使用版本控制。
你也可以在photoshop中修复这个…
打开你的。png文件。 文件->另存为并在打开的对话框中取消选中“ICC配置文件:sRGB IEC61966-2.1” 取消勾选“作为副本”。 勇敢地保存你原来的。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)
为了补充Glenn的精彩回答,以下是我找到错误文件的方法:
find . -name "*.png" -type f -print0 | xargs \
-0 pngcrush_1_8_8_w64.exe -n -q > pngError.txt 2>&1
我使用find和xargs,因为pngcrush不能处理大量的参数(由**/*.png返回)。-print0和-0用于处理包含空格的文件名。
然后在输出中搜索这些行:iCCP:不识别已编辑的已知sRGB配置文件。
./Installer/Images/installer_background.png:
Total length of data found in critical chunks = 11286
pngcrush: iCCP: Not recognizing known sRGB profile that has been edited
对于每一个,运行mogrify来修复它们。
mogrify ./Installer/Images/installer_background.png
这样做可以防止提交更改存储库中的每个png文件,而实际上只修改了几个。另外,它的优点是可以准确地显示出哪些文件有错误。
我在Windows上用Cygwin控制台和zsh shell进行了测试。再次感谢格伦,他提供了上面的大部分内容,我只是添加了一个答案,因为它通常比评论更容易找到:)