当前位置:   article > 正文

known incorrect sRGB profile 问题解决方案

known incorrect srgb profile

由于Qt新版本对png文件的检测比较严格,所以有了  libpng warning: iCCP: known incorrect sRGB profile 的提醒,我的解决办法是写一个程序直接转换掉,就可以去掉对应的提醒。

源码如下:

ChangePNG.cpp

  1. #include "ChangePNG.h"
  2. #include "ui_ChangePNG.h"
  3. #include <QFile>
  4. #include <QFileDialog>
  5. #include <QDebug>
  6. ChangePNG::ChangePNG(QWidget *parent) :
  7. QMainWindow(parent),
  8. ui(new Ui::ChangePNG)
  9. {
  10. ui->setupUi(this);
  11. creatAction();
  12. menuAddAction();
  13. toolBarAddAction();
  14. }
  15. void ChangePNG::creatAction()
  16. {
  17. //打开文件的Action
  18. m_openFileAction = new QAction(this);
  19. m_openFileAction->setText("打开");
  20. m_openFileAction->setStatusTip("打开文件");
  21. m_openFileAction->setIcon(QIcon(":/picture/images/document-open.png"));
  22. connect(m_openFileAction, SIGNAL(triggered(bool)), this, SLOT(openFile()));
  23. //保存文件的Action
  24. m_saveFileAction = new QAction(this);
  25. m_saveFileAction->setText("保存");
  26. m_saveFileAction->setStatusTip("保存文件");
  27. m_saveFileAction->setIcon(QIcon(":/picture/images/document-save.png"));
  28. //另外一种连接信号和槽的方法
  29. connect(m_saveFileAction, &QAction::triggered, this, &ChangePNG::saveFile);
  30. }
  31. void ChangePNG::menuAddAction()
  32. {
  33. menu = new QMenu("文件");
  34. menu->addAction(m_openFileAction);
  35. menu->addAction(m_saveFileAction);
  36. ui->menuBar->addMenu(menu);
  37. }
  38. void ChangePNG::toolBarAddAction()
  39. {
  40. ui->mainToolBar->addAction(m_openFileAction);
  41. ui->mainToolBar->addAction(m_saveFileAction);
  42. }
  43. void ChangePNG::openFile()
  44. {
  45. QStringList fileList = QFileDialog::getOpenFileNames(this,
  46. tr("选择要转换的PNG格式的图片"),
  47. tr(""),
  48. "image(*.png)");
  49. QStringList::iterator it = fileList.begin();
  50. QPixmap pixmap;
  51. QFile file;
  52. QString oldFileString = NULL;
  53. QString newFileString = NULL;
  54. while(it != fileList.end()) //把所有的文件遍历一遍
  55. {
  56. file.setFileName(*it);
  57. QFileInfo fileinfo(file.fileName());
  58. QString filename(fileinfo.fileName()); //获取文件名称
  59. QString fileAbsoluteDir(fileinfo.absolutePath()); //绝对路径
  60. QString newName = filename;
  61. oldFileString.append(newName+tr("\n"));
  62. newName.replace(newName.length()-4, 4, tr("old.png")); //重新设定文件要修改文件的名字
  63. newFileString.append(newName+tr("\n"));
  64. newName = fileAbsoluteDir+tr("/")+newName; //计算新文件的绝对路径
  65. if(file.rename(*it, newName)) //修改文件的名字防止冲突
  66. {
  67. pixmap.load(newName); //设定要加载图片的绝对路径
  68. file.setFileName(*it); //以旧的文件名字来命名新生成的
  69. file.open(QIODevice::WriteOnly); //以写的方式打开该文件
  70. pixmap.save(&file, "PNG"); //以png格式保存文件
  71. file.close(); //关闭文件
  72. }
  73. else
  74. {
  75. qDebug()<<"修改文件名失败!";
  76. }
  77. ui->oldFile_textEdit->setText(oldFileString);
  78. ui->newFile_textEdit->setText(newFileString);
  79. it++;
  80. }
  81. }
  82. void ChangePNG::saveFile()
  83. {
  84. }
  85. ChangePNG::~ChangePNG()
  86. {
  87. delete ui;
  88. }

 ChangePNG.h

  1. #ifndef CHANGEPNG_H
  2. #define CHANGEPNG_H
  3. #include <QMainWindow>
  4. namespace Ui {
  5. class ChangePNG;
  6. }
  7. class ChangePNG : public QMainWindow
  8. {
  9. Q_OBJECT
  10. public:
  11. explicit ChangePNG(QWidget *parent = 0);
  12. ~ChangePNG();
  13. private:
  14. void creatAction();
  15. void menuAddAction();
  16. void toolBarAddAction();
  17. private:
  18. QMenu* menu;
  19. QAction* m_openFileAction;
  20. QAction* m_saveFileAction;
  21. private slots:
  22. void openFile();
  23. void saveFile();
  24. private:
  25. Ui::ChangePNG *ui;
  26. };
  27. #endif // CHANGEPNG_H

源码:https://download.csdn.net/download/duxingheiying1041/10421180

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/205861
推荐阅读
  

闽ICP备14008679号