当前位置:   article > 正文

解决libpng warning: iCCP: known incorrect sRGB profile

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");
  • 1
  • 2

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

#ifndef SOLVELIBPNGWARNING_H
#define SOLVELIBPNGWdARNING_H


#include <QtWidgets>
#include <QWidget>


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
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
#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());
        }
    }


}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/108289
推荐阅读
相关标签
  

闽ICP备14008679号