From 74725b08e64ad2029331f6e83ae6ab0f84bb62cb Mon Sep 17 00:00:00 2001 From: feiyangqingyun Date: Sun, 13 Oct 2019 10:15:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EPNG=E8=AD=A6=E5=91=8A?= =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +- pngtool/frmpngtool.cpp | 74 ++++++++++++++++++++++++++++++++++++++++++ pngtool/frmpngtool.h | 28 ++++++++++++++++ pngtool/frmpngtool.ui | 68 ++++++++++++++++++++++++++++++++++++++ pngtool/main.cpp | 31 ++++++++++++++++++ pngtool/pngtool.pro | 20 ++++++++++++ 6 files changed, 223 insertions(+), 1 deletion(-) create mode 100644 pngtool/frmpngtool.cpp create mode 100644 pngtool/frmpngtool.h create mode 100644 pngtool/frmpngtool.ui create mode 100644 pngtool/main.cpp create mode 100644 pngtool/pngtool.pro diff --git a/README.md b/README.md index f559d11..e2b41bc 100644 --- a/README.md +++ b/README.md @@ -18,4 +18,5 @@ Qt编写的一些开源的demo,包括串口调试助手、网络调试助手 | 12 | framelesswidget | 通用无边框拖动拉伸类 | | 13 | ipaddress | IP地址输入控件 | | 14 | bgdemo | 无边框背景透明窗体 | -| 15 | dbpage | 通用数据库翻页查询 | \ No newline at end of file +| 15 | dbpage | 通用数据库翻页查询 | +| 16 | pngtool | PNG图片警告去除工具 | \ No newline at end of file diff --git a/pngtool/frmpngtool.cpp b/pngtool/frmpngtool.cpp new file mode 100644 index 0000000..5005dd0 --- /dev/null +++ b/pngtool/frmpngtool.cpp @@ -0,0 +1,74 @@ +#include "frmpngtool.h" +#include "ui_frmpngtool.h" +#include "qfile.h" +#include "qfiledialog.h" +#include "qdebug.h" + +frmPngTool::frmPngTool(QWidget *parent) : QWidget(parent), ui(new Ui::frmPngTool) +{ + ui->setupUi(this); + ui->progress->setRange(0, 0); + ui->progress->setValue(0); +} + +frmPngTool::~frmPngTool() +{ + delete ui; +} + +void frmPngTool::on_btnFile_clicked() +{ + QString file = QFileDialog::getOpenFileName(this, "选择png文件", qApp->applicationDirPath(), "png图片文件(*.png)"); + if (!file.isEmpty()) { + ui->txtFile->setText(file); + ui->progress->setValue(0); + } +} + +void frmPngTool::on_btnDir_clicked() +{ + QString dir = QFileDialog::getExistingDirectory(this, "选择目录"); + if (!dir.isEmpty()) { + ui->txtDir->setText(dir); + ui->progress->setValue(0); + } +} + +void frmPngTool::on_btnOk_clicked() +{ + files.clear(); + + //将单个文件加入队列 + QString currentFile = ui->txtFile->text().trimmed(); + if (currentFile.isEmpty()) { + files.append(currentFile); + } + + //将该目录下的所有png文件存入链表 + QString currentDir = ui->txtDir->text().trimmed(); + if (!currentDir.isEmpty()) { + QDir imagePath(currentDir); + QStringList filter; + filter << "*.png"; + QStringList list = imagePath.entryList(filter); + + foreach (QString str, list) { + files.append(currentDir + "/" + str); + } + } + + ui->progress->setRange(0, files.count()); + ui->progress->setValue(0); + + int count = 0; + foreach (QString file, files) { + qDebug() << "current file:" << file; + QImage image(file); + image.save(file, "png"); + count++; + ui->progress->setValue(count); + qApp->processEvents(); + } + + qDebug() << "finsh"; +} diff --git a/pngtool/frmpngtool.h b/pngtool/frmpngtool.h new file mode 100644 index 0000000..7214868 --- /dev/null +++ b/pngtool/frmpngtool.h @@ -0,0 +1,28 @@ +#ifndef FRMPNGTOOL_H +#define FRMPNGTOOL_H + +#include + +namespace Ui { +class frmPngTool; +} + +class frmPngTool : public QWidget +{ + Q_OBJECT + +public: + explicit frmPngTool(QWidget *parent = 0); + ~frmPngTool(); + +private slots: + void on_btnFile_clicked(); + void on_btnDir_clicked(); + void on_btnOk_clicked(); + +private: + Ui::frmPngTool *ui; + QStringList files; +}; + +#endif // FRMPNGTOOL_H diff --git a/pngtool/frmpngtool.ui b/pngtool/frmpngtool.ui new file mode 100644 index 0000000..ca04371 --- /dev/null +++ b/pngtool/frmpngtool.ui @@ -0,0 +1,68 @@ + + + frmPngTool + + + + 0 + 0 + 437 + 105 + + + + Form + + + + + + + + + 选择目录 + + + + + + + + + + 选择文件 + + + + + + + 24 + + + + + + + 执行转换 + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/pngtool/main.cpp b/pngtool/main.cpp new file mode 100644 index 0000000..c2ef32c --- /dev/null +++ b/pngtool/main.cpp @@ -0,0 +1,31 @@ +#pragma execution_character_set("utf-8") + +#include "frmpngtool.h" +#include +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + a.setFont(QFont("Microsoft Yahei", 9)); + +#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0)) +#if _MSC_VER + QTextCodec *codec = QTextCodec::codecForName("gbk"); +#else + QTextCodec *codec = QTextCodec::codecForName("utf-8"); +#endif + QTextCodec::setCodecForLocale(codec); + QTextCodec::setCodecForCStrings(codec); + QTextCodec::setCodecForTr(codec); +#else + QTextCodec *codec = QTextCodec::codecForName("utf-8"); + QTextCodec::setCodecForLocale(codec); +#endif + + frmPngTool w; + w.setWindowTitle("PNG图片警告去除工具"); + w.show(); + + return a.exec(); +} diff --git a/pngtool/pngtool.pro b/pngtool/pngtool.pro new file mode 100644 index 0000000..e3e86a8 --- /dev/null +++ b/pngtool/pngtool.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2017-02-08T09:21:04 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = pngtool +TEMPLATE = app +DESTDIR = $$PWD/../bin +CONFIG += warn_off + +SOURCES += main.cpp +SOURCES += frmpngtool.cpp +HEADERS += frmpngtool.h +FORMS += frmpngtool.ui +