赞
踩
我们使用 Qt 或Python 开发时,有时会到遇
libpng warning: iCCP: known incorrect sRGB profile
在控制台一直打印,需要解决;
主要是 libpng 这个库兼容性问题;可以去掉 sRGB 中的 iCCP;
由于文件较多,可以将所有文件合并到一个文件夹下:再遍历一下有问题的 png 文件,处理一下;
Python:
- rom PIL import Image
-
- import os
-
-
- directory = "C:/test"
-
- def check_iccp_profile(file_path):
- try:
-
- # 尝试打开图像文件
-
- with Image.open(file_path) as img:
-
- # 获取图像的信息
-
- img_info = img.info
-
- # 检查图像信息中是否包含 'icc_profile'
-
- if 'icc_profile' in img_info:
- # 如果 icc_profile 存在,输出文件路径和相关信息
-
- print(f'发现 ICC 配置文件:{file_path}')
-
- # 这里可以添加进一步的处理,例如打印或保存 icc_profile 的内容
-
- except IOError as e:
-
- # 捕获并打印错误信息
-
- print(f'错误:{file_path} - {e}')
-
-
- def find_images_with_iccp_warning(directory):
- # 遍历目录中的所有文件
-
- for root, dirs, files in os.walk(directory):
-
- for file in files:
-
- # 检查文件扩展名是否为 PNG
-
- if file.lower().endswith('.png'):
- file_path = os.path.join(root, file)
-
- check_iccp_profile(file_path)
-
-
- # 调用函数检查目录
-
- find_images_with_iccp_warning(directory)
输出:
- 发现 ICC 配置文件:C:/Users/test/Desktop\b\bcct_disabled.png
- 发现 ICC 配置文件:C:/Users/test/Desktop\b\caa_disabled.png
使用PS打开图片,然后点击编辑,再打开指定配置文件
可以改成,第一个:不对此文档应用色彩管理;网上也有选择最后一个;
改完后,确定保存;
2.使用 Python 程序转一下;(libpng warning: iCCP: known incorrect sRGB profile 警告,问题解决-CSDN博客)
单张:注意路径
- import cv2
- from skimage import io
-
- image = io.imread(path)
- image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)
- cv2.imencode('.png',image)[1].tofile(path)
多张:
- import os
- from tqdm import tqdm
- import cv2
- from skimage import io
- #import os
- path = r"你的路径" #path后面记得加 /
-
- fileList = os.listdir(path)
- for i in tqdm(fileList):
- image = io.imread(path+i) # image = io.imread(os.path.join(path, i))
- image = cv2.cvtColor(image, cv2.COLOR_RGBA2BGRA)
- cv2.imencode('.png',image)[1].tofile(path+i)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。