新增PNG警告去除工具

master
feiyangqingyun 2019-10-13 10:15:27 +08:00
parent b017e2d1ae
commit 74725b08e6
6 changed files with 223 additions and 1 deletions

View File

@ -18,4 +18,5 @@ Qt编写的一些开源的demo包括串口调试助手、网络调试助手
| 12 | framelesswidget | 通用无边框拖动拉伸类 | | 12 | framelesswidget | 通用无边框拖动拉伸类 |
| 13 | ipaddress | IP地址输入控件 | | 13 | ipaddress | IP地址输入控件 |
| 14 | bgdemo | 无边框背景透明窗体 | | 14 | bgdemo | 无边框背景透明窗体 |
| 15 | dbpage | 通用数据库翻页查询 | | 15 | dbpage | 通用数据库翻页查询 |
| 16 | pngtool | PNG图片警告去除工具 |

74
pngtool/frmpngtool.cpp Normal file
View File

@ -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";
}

28
pngtool/frmpngtool.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef FRMPNGTOOL_H
#define FRMPNGTOOL_H
#include <QWidget>
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

68
pngtool/frmpngtool.ui Normal file
View File

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>frmPngTool</class>
<widget class="QWidget" name="frmPngTool">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>437</width>
<height>105</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLineEdit" name="txtDir"/>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="btnDir">
<property name="text">
<string>选择目录</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="txtFile"/>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="btnFile">
<property name="text">
<string>选择文件</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QProgressBar" name="progress">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="btnOk">
<property name="text">
<string>执行转换</string>
</property>
</widget>
</item>
<item row="3" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

31
pngtool/main.cpp Normal file
View File

@ -0,0 +1,31 @@
#pragma execution_character_set("utf-8")
#include "frmpngtool.h"
#include <QApplication>
#include <QTextCodec>
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();
}

20
pngtool/pngtool.pro Normal file
View File

@ -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