iCCP: known incorrect sRGB profile

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/tianmaxingkong_/article/details/54333416
在win7系统中,微软提高了对图片质量的检测,项目中的图片可能会弹出下面的警告框:

"iccp known incorrect sRGB profile" 警告

(不同系统上的ImageMagic下载地址:http://www.imagemagick.org/script/binary-releases.php
这不是错误,但为了提高用户的体验,需要将这个框 去除,可以使用ImageMagick对图片进行转换,其实是该软件中magick.exe这个工具进行图片转换的:

e.g. 使用magick.exe对D盘下的logo_sys.png进行转换,在cmd中执行:
magick.exe D:\logo_sys.png D:\logo_sys.png
下面的程序可以批量处理文件夹下所有的图片文件:
import os
# rootPath是需要转换的图片所在的根目录
rootPath = "D:/icon"
# magick.exe所在的路径
commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick.exe'
# 获得rootPath目录下所有图片文件的全路径
def FindExamAllFiles():
    tmp = []
    for root, dirs, files in os.walk(rootPath):
        for filepath in files:
            imgFileFullPath = os.path.join(root, filepath)
            if imgFileFullPath.endswith('.png'):
                tmp.append(imgFileFullPath)
    return tmp

if __name__ == "__main__":
    pngPathList = FindExamAllFiles()
    for pngPath in pngPathList:
        # 拼凑cmd命令
        command = "{0} {1} {2}".format(commandTool, pngPath, pngPath)
        os.system(command)

要是我们的应用会涉及到用户自主导入图片的操作,为了保证不弹出sRGB警告框,可以在每次读入图片文件之后,调用下面的函数,首先对图片进行sRGB处理: (winXP下不会有sRGB的警告,win7-32bit和win7-64bit下处理图片sRGB警告的工具版本不同)
import platform
# 处理文件夹中单个的图片
def convertsRGBImageFromTmp(iconName):
    winVerName = platform.win32_ver()[0]
    if winVerName != None:
        if winVerName.upper() == '7':
            arch = platform.architecture()[0]
            if arch.upper() == '64BIT':
                commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick_64.exe'
            else:
                commandTool = os.getcwdu()+os.sep+"tools"+os.sep+'magick.exe'

            pngPath =  os.getcwdu()+os.sep+'tmp'+os.sep+iconName
            command = "{0} {1} {2}".format(commandTool, pngPath, pngPath)
            try:
                os.system(command)
            except:
                pass
        else:
            return
    pass
因为sRGB的检测是在win7以及之后版本的系统上才有的,在XP的系统上是无需进行该操作的,Python提供了platform这个库来检测当前系统的版本,我们可以使用platform.win32_ver()[0]获得版本的名称,并进行不同的操作。

猜你喜欢

转载自blog.csdn.net/tianmaxingkong_/article/details/54333416