解决libpng warning: iCCP: known incorrect sRGB profile

解决libpng warning: iCCP: known incorrect sRGB profile

出现这个警告是因为png格式不正确,解决这个问题只需要用QImage重新保存下png图片就可以了。
例如:

QImage im;
im.load("*.png");
im.save("*.png");

直接上个批量处理的代码吧,功能很简单。对一个文件内的所有png格式的照片进行一次转换。

#ifndef SOLVELIBPNGWARNING_H
#define SOLVELIBPNGWdARNING_H


#include 
#include 


class SolveLibpngWarning : public QWidget
{
    Q_OBJECT


public:
    SolveLibpngWarning(QWidget *parent = 0);
    ~SolveLibpngWarning();


private slots:
    void selectDirSlot();
    void destinationSlot();
    void transformBtnSlot();


private:


    QString urlString;
    QString destinationPath;
    QLineEdit *filePathEdit;
    QPushButton *selectDirBtn;
    QLineEdit *destinationEdit;
    QPushButton *destinationBtn;
    QPushButton *transformBtn;
};


#endif // SOLVELIBPNGWARNING_H
#include "SolveLibpngWarning.h"


SolveLibpngWarning::SolveLibpngWarning(QWidget *parent)
    : QWidget(parent)
{
    this->resize(400,250);
    filePathEdit = new QLineEdit(this);
    filePathEdit->setFixedWidth(200);
    filePathEdit->move(60,50);
    selectDirBtn = new QPushButton(QStringLiteral("源目录"),this);
    selectDirBtn->setFixedWidth(60);
    selectDirBtn->move(280,50);


    destinationEdit = new QLineEdit(this);
    destinationEdit->setFixedWidth(200);
    destinationEdit->move(60,100);
    destinationBtn = new QPushButton(QStringLiteral("终目录"),this);
    destinationBtn->setFixedWidth(60);
    destinationBtn->move(280,100);


    transformBtn = new QPushButton(QStringLiteral("开始转换"),this);
    transformBtn->setFixedWidth(60);
    transformBtn->move(170,150);


    connect(selectDirBtn,SIGNAL(clicked(bool)),this,SLOT(selectDirSlot()));
    connect(destinationBtn,SIGNAL(clicked(bool)),this,SLOT(destinationSlot()));
    connect(transformBtn,SIGNAL(clicked(bool)),this,SLOT(transformBtnSlot()));
}


SolveLibpngWarning::~SolveLibpngWarning()
{


}


/*
*brief:选择存放图片文件的源目录
*/
void SolveLibpngWarning::selectDirSlot()
{
    urlString = QFileDialog::getExistingDirectory(this,QStringLiteral("选择需要转换的文件夹"),"C:/");
    filePathEdit->setText(urlString);
}


/*
*brief:选择转换生成生成的目录
*/
void SolveLibpngWarning::destinationSlot()
{
    destinationPath = QFileDialog::getExistingDirectory(this,QStringLiteral("选择需要转换的文件夹"),filePathEdit->text());
    destinationEdit->setText(destinationPath);
}


/*
*brief:对源目录下的png格式的图片加载和保存
*/
void SolveLibpngWarning::transformBtnSlot()
{
    QDir dir(filePathEdit->text());
    dir.setFilter(QDir::Files);


    QDir dir2(destinationEdit->text());
    if(!dir2.exists()){
        dir2.mkpath(destinationEdit->text());
    }


    QFileInfoList allFileInfo = dir.entryInfoList();
    for( int i=0;i<allFileInfo.count();i++ ) {//文件过滤
        if( allFileInfo.at(i).completeSuffix() == "png" ) {
            QImage im1;
            im1.load(urlString+"/"+allFileInfo.at(i).fileName());
            im1.save(destinationEdit->text()+"/"+allFileInfo.at(i).fileName());
        }
    }


}

你可能感兴趣的:(QT)