增加:选区马赛克

This commit is contained in:
sonichy 2018-12-05 16:10:31 +08:00
parent b6e8b46cba
commit 6267fc1169
10 changed files with 100 additions and 15 deletions

BIN
HTYPaint

Binary file not shown.

View File

@ -3,7 +3,8 @@
已编译好的 HTYPaint 程序适用于 64 位 Linux 系统 Qt5 环境,双击运行,其他版本自行编译。 已编译好的 HTYPaint 程序适用于 64 位 Linux 系统 Qt5 环境,双击运行,其他版本自行编译。
![alt](preview.png) ![alt](preview.png)
### 1.10 新增选区马赛克
![alt](mosaic.png)
### 1.7 新增箭头工具,颜色透明工具 ### 1.7 新增箭头工具,颜色透明工具
### 1.4 新增绘制透明图形 ### 1.4 新增绘制透明图形
### 1.3 新增模糊 ### 1.3 新增模糊

BIN
blur.jpg

Binary file not shown.

Before

Width:  |  Height:  |  Size: 168 KiB

After

Width:  |  Height:  |  Size: 399 KiB

BIN
gray.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 5.2 MiB

View File

@ -671,7 +671,7 @@ void ImageWidget::transparent()
h = imgtemp.height(); h = imgtemp.height();
QImage imgTansparent(w,h,QImage::Format_ARGB32); QImage imgTansparent(w,h,QImage::Format_ARGB32);
for(int x=0; x<w; x++){ for(int x=0; x<w; x++){
for(int y=0;y<h; y++){ for(int y=0; y<h; y++){
QRgb RGB = image.pixel(x,y); QRgb RGB = image.pixel(x,y);
if (RGB == pen.color().rgb()){ if (RGB == pen.color().rgb()){
QRgb RGBT = qRgba(qRed(RGB),qGreen(RGB),qBlue(RGB),0); QRgb RGBT = qRgba(qRed(RGB),qGreen(RGB),qBlue(RGB),0);
@ -694,7 +694,7 @@ void ImageWidget::blur(int p)
if(startPnt.x()>endPnt.x() && startPnt.y()<endPnt.y()){xs=endPnt.x(); ys=startPnt.y(); xe=startPnt.x(); ye=endPnt.y();} if(startPnt.x()>endPnt.x() && startPnt.y()<endPnt.y()){xs=endPnt.x(); ys=startPnt.y(); xe=startPnt.x(); ye=endPnt.y();}
if(startPnt.x()>endPnt.x() && startPnt.y()>endPnt.y()){xs=endPnt.x(); ys=endPnt.y(); xe=startPnt.x(); ye=startPnt.y();} if(startPnt.x()>endPnt.x() && startPnt.y()>endPnt.y()){xs=endPnt.x(); ys=endPnt.y(); xe=startPnt.x(); ye=startPnt.y();}
if(startPnt.x()<endPnt.x() && startPnt.y()>endPnt.y()){xs=startPnt.x(); ys=endPnt.y(); xe=endPnt.x(); ye=startPnt.y();} if(startPnt.x()<endPnt.x() && startPnt.y()>endPnt.y()){xs=startPnt.x(); ys=endPnt.y(); xe=endPnt.x(); ye=startPnt.y();}
QImage imgBlur(qAbs(endPnt.x()-startPnt.x())+2,qAbs(endPnt.y()-startPnt.y())+2,QImage::Format_RGB32); QImage imgBlur(qAbs(endPnt.x()-startPnt.x())+2, qAbs(endPnt.y()-startPnt.y())+2, QImage::Format_RGB32);
for(int x=xs; x<xe+2; x++){ for(int x=xs; x<xe+2; x++){
for(int y=ys;y<ye+2; y++){ for(int y=ys;y<ye+2; y++){
int red=0, green=0, blue=0, pc=0; int red=0, green=0, blue=0, pc=0;
@ -730,3 +730,28 @@ bool ImageWidget::eventFilter(QObject *obj, QEvent *event)
} }
return false; return false;
} }
void ImageWidget::mosaic(int p)
{
imgtemp = image;
update();
int xs,xe,ys,ye;
if(startPnt.x()<endPnt.x() && startPnt.y()<endPnt.y()){xs=startPnt.x(); ys=startPnt.y(); xe=endPnt.x(); ye=endPnt.y();}
if(startPnt.x()>endPnt.x() && startPnt.y()<endPnt.y()){xs=endPnt.x(); ys=startPnt.y(); xe=startPnt.x(); ye=endPnt.y();}
if(startPnt.x()>endPnt.x() && startPnt.y()>endPnt.y()){xs=endPnt.x(); ys=endPnt.y(); xe=startPnt.x(); ye=startPnt.y();}
if(startPnt.x()<endPnt.x() && startPnt.y()>endPnt.y()){xs=startPnt.x(); ys=endPnt.y(); xe=endPnt.x(); ye=startPnt.y();}
QImage imgMosaic(qAbs(endPnt.x()-startPnt.x())+2, qAbs(endPnt.y()-startPnt.y())+2, QImage::Format_RGB32);
QPainter painterm(&imgMosaic);
for(int x=xs; x<xe; x+=p){
for(int y=ys; y<ye; y+=p){
QRgb rgb = image.pixel(x,y);
QColor colorm(qRed(rgb),qGreen(rgb),qBlue(rgb));
painterm.setPen(QPen(colorm));
painterm.setBrush(QBrush(colorm));
painterm.drawRect(QRect(x-xs,y-ys,p,p));
}
}
QPainter painter(&imgtemp);
painter.drawImage(xs,ys,imgMosaic);
update();
}

View File

@ -58,6 +58,7 @@ public:
void invert(); void invert();
void transparent(); void transparent();
void blur(int p); void blur(int p);
void mosaic(int p);
public slots: public slots:
void newfile(); void newfile();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 5.2 MiB

View File

@ -60,15 +60,6 @@ MainWindow::MainWindow(QWidget *parent) :
scrollArea->widget()->setMinimumSize(600,500); scrollArea->widget()->setMinimumSize(600,500);
setCentralWidget(scrollArea); setCentralWidget(scrollArea);
ui->action_new->setIcon(style()->standardIcon(QStyle::SP_FileDialogNewFolder));
ui->action_open->setIcon(style()->standardIcon(QStyle::SP_DialogOpenButton));
ui->action_save->setIcon(style()->standardIcon(QStyle::SP_DialogSaveButton));
ui->action_quit->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
ui->action_undo->setIcon(style()->standardIcon(QStyle::SP_DialogCancelButton));
ui->action_quit->setIcon(style()->standardIcon(QStyle::SP_DialogCloseButton));
ui->action_setWallpaper->setIcon(style()->standardIcon(QStyle::SP_ComputerIcon));
ui->action_about->setIcon(style()->standardIcon(QStyle::SP_DialogHelpButton));
btnColorBorder = new QToolButton(this); btnColorBorder = new QToolButton(this);
btnColorBorder->setText(""); btnColorBorder->setText("");
btnColorBorder->setToolTip("边框"); btnColorBorder->setToolTip("边框");
@ -147,7 +138,7 @@ void MainWindow::resizeEvent(QResizeEvent *event)
void MainWindow::on_action_changelog_triggered() void MainWindow::on_action_changelog_triggered()
{ {
QString s = "1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件没引用资源文件引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。"; QString s = "1.10\n(2018-12)\n增加:选区马赛克。\n\n1.9\n(2018-11)\n增加:画笔粗细快捷键,画图更加方便。\n\n1.8\n(2018-05)\n修复:删除选区有虚线框,从右键打开方式无法打开文件。\n\n1.7\n(2017-11)\n颜色透明工具,取色后在边框色、填充色显示,超出边界清空鼠标位置信息。\n增加灰色背景,凸显绘图区域。\n优化代码。\n(2017-10)\n简化工具信号简化setCursor()。\n(2017-09)\n增加箭头工具。\n增加抗锯齿。\n\n1.6\n(2017-07)\n更新日志消息窗口写不下了,改成带滚动条的文本框。\n自定义信号结合事件过滤器,把鼠标移动位置发送到主窗体信息栏。\n增加拖放打开文件。\n(2017-06)\n使用自定义信号解决子类发信息给主窗体状态栏问题致谢rekols。\n(2017-05)\n右键打开文件记忆文件路径。\n\n1.5 (2017-04)\n透明色反色不改变。\n增加取色工具,橡皮擦颜色不再固定为白色,而是填充色。\n\n1.4 (2017-03)\n支持命令行打开文件和打开方式打开文件。\n修复鼠标指针引用本地文件没引用资源文件引起启动path参数改变不能加载图标的问题。\n菜单的SIGNAL-SLOT改为on_action_triggered()\n修复PNG图片裁剪丢失透明度问题。\n新建图像为透明图像。\n\n1.3 (2017-03)\n实现选区模糊。\n加入模糊滤镜。\n\n1.2 (2017-02)\n文件名显示在窗口标题栏。\n区别保存和另存为。\n增加导入图片。\n\n1.1 (2017-01)\n新增灰度、反色。\n\n1.0 (2017-01)\n解决删除选区后画不出选框的问题。\n恢复撤销。\n增加全选。\n实现选区或剪贴板移动!\n保存时自动获取打开文件的路径。\n增加按像素、比例缩放。\n实现在属性窗口设置画布大小。\n2016-12\n增加快捷键控制选框及其边框移动。\n绘图代码从MainWindow向imageWidget迁移。\n实现水平镜像、垂直镜像。\n实现放大、缩小、原始大小。\n为了增加滚动条增加自定义imageWidget。\n状态栏显示绘图详情。\n复制选区到系统剪贴板,从系统剪贴板获取图像粘贴。\n优化颜色选择交互。\n增加撤销、重做功能有BUG。\n设为壁纸。\n画选区,剪裁选区。\n新建图片,打开图片,保存图片。\n实现画点、线、框、圆、字。";
QDialog *dialog = new QDialog; QDialog *dialog = new QDialog;
dialog->setWindowTitle("更新历史"); dialog->setWindowTitle("更新历史");
dialog->setFixedSize(400,300); dialog->setFixedSize(400,300);
@ -517,6 +508,11 @@ void MainWindow::on_action_blur_triggered()
imageWidget->blur(spinbox->value()); imageWidget->blur(spinbox->value());
} }
void MainWindow::on_action_mosaic_triggered()
{
imageWidget->mosaic(spinbox->value());
}
void MainWindow::dragEnterEvent(QDragEnterEvent *e) void MainWindow::dragEnterEvent(QDragEnterEvent *e)
{ {
//if(e->mimeData()->hasFormat("text/uri-list")) //只能打开文本文件 //if(e->mimeData()->hasFormat("text/uri-list")) //只能打开文本文件

View File

@ -49,7 +49,6 @@ private slots:
void on_action_changelog_triggered(); void on_action_changelog_triggered();
void on_action_aboutQt_triggered(); void on_action_aboutQt_triggered();
void on_action_about_triggered(); void on_action_about_triggered();
void on_action_undo_triggered(); void on_action_undo_triggered();
void on_action_redo_triggered(); void on_action_redo_triggered();
void on_action_copy_triggered(); void on_action_copy_triggered();
@ -61,12 +60,15 @@ private slots:
void on_action_gray_triggered(); void on_action_gray_triggered();
void on_action_invert_triggered(); void on_action_invert_triggered();
void on_action_blur_triggered(); void on_action_blur_triggered();
void on_action_mosaic_triggered();
void on_action_transparent_triggered(); void on_action_transparent_triggered();
void on_actionRotateLeft_triggered(); void on_actionRotateLeft_triggered();
void on_actionRotateRight_triggered(); void on_actionRotateRight_triggered();
void on_actionMirrorHorizontal_triggered(); void on_actionMirrorHorizontal_triggered();
void on_actionMirrorVertical_triggered(); void on_actionMirrorVertical_triggered();
void on_actionFont_triggered(); void on_actionFont_triggered();
void setColorFill(); void setColorFill();
void setColorBorder(); void setColorBorder();
void spinValueChange(int); void spinValueChange(int);

View File

@ -27,7 +27,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1050</width> <width>1050</width>
<height>24</height> <height>23</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menu_file"> <widget class="QMenu" name="menu_file">
@ -65,6 +65,7 @@
<addaction name="action_invert"/> <addaction name="action_invert"/>
<addaction name="action_blur"/> <addaction name="action_blur"/>
<addaction name="action_transparent"/> <addaction name="action_transparent"/>
<addaction name="action_mosaic"/>
</widget> </widget>
<widget class="QMenu" name="menu_about"> <widget class="QMenu" name="menu_about">
<property name="title"> <property name="title">
@ -113,6 +114,9 @@
</widget> </widget>
<widget class="QStatusBar" name="statusBar"/> <widget class="QStatusBar" name="statusBar"/>
<action name="action_open"> <action name="action_open">
<property name="icon">
<iconset theme="document-open"/>
</property>
<property name="text"> <property name="text">
<string>打开</string> <string>打开</string>
</property> </property>
@ -121,6 +125,9 @@
</property> </property>
</action> </action>
<action name="action_save"> <action name="action_save">
<property name="icon">
<iconset theme="document-save"/>
</property>
<property name="text"> <property name="text">
<string>保存</string> <string>保存</string>
</property> </property>
@ -129,6 +136,9 @@
</property> </property>
</action> </action>
<action name="action_saveas"> <action name="action_saveas">
<property name="icon">
<iconset theme="document-save-as"/>
</property>
<property name="text"> <property name="text">
<string>另存为</string> <string>另存为</string>
</property> </property>
@ -137,6 +147,9 @@
</property> </property>
</action> </action>
<action name="action_quit"> <action name="action_quit">
<property name="icon">
<iconset theme="application-exit"/>
</property>
<property name="text"> <property name="text">
<string>退出</string> <string>退出</string>
</property> </property>
@ -145,6 +158,9 @@
</property> </property>
</action> </action>
<action name="action_undo"> <action name="action_undo">
<property name="icon">
<iconset theme="edit-undo"/>
</property>
<property name="text"> <property name="text">
<string>撤销</string> <string>撤销</string>
</property> </property>
@ -153,6 +169,9 @@
</property> </property>
</action> </action>
<action name="action_redo"> <action name="action_redo">
<property name="icon">
<iconset theme="edit-redo"/>
</property>
<property name="text"> <property name="text">
<string>重做</string> <string>重做</string>
</property> </property>
@ -161,6 +180,9 @@
</property> </property>
</action> </action>
<action name="action_copy"> <action name="action_copy">
<property name="icon">
<iconset theme="edit-copy"/>
</property>
<property name="text"> <property name="text">
<string>复制</string> <string>复制</string>
</property> </property>
@ -169,6 +191,9 @@
</property> </property>
</action> </action>
<action name="action_cut"> <action name="action_cut">
<property name="icon">
<iconset theme="edit-cut"/>
</property>
<property name="text"> <property name="text">
<string>剪切</string> <string>剪切</string>
</property> </property>
@ -177,6 +202,9 @@
</property> </property>
</action> </action>
<action name="action_paste"> <action name="action_paste">
<property name="icon">
<iconset theme="edit-paste"/>
</property>
<property name="text"> <property name="text">
<string>粘贴</string> <string>粘贴</string>
</property> </property>
@ -185,6 +213,9 @@
</property> </property>
</action> </action>
<action name="action_selectAll"> <action name="action_selectAll">
<property name="icon">
<iconset theme="edit-select-all"/>
</property>
<property name="text"> <property name="text">
<string>全选</string> <string>全选</string>
</property> </property>
@ -193,6 +224,9 @@
</property> </property>
</action> </action>
<action name="action_delete"> <action name="action_delete">
<property name="icon">
<iconset theme="edit-delete"/>
</property>
<property name="text"> <property name="text">
<string>删除</string> <string>删除</string>
</property> </property>
@ -223,6 +257,9 @@
</property> </property>
</action> </action>
<action name="action_property"> <action name="action_property">
<property name="icon">
<iconset theme="document-properties"/>
</property>
<property name="text"> <property name="text">
<string>属性</string> <string>属性</string>
</property> </property>
@ -231,11 +268,17 @@
</property> </property>
</action> </action>
<action name="action_setWallpaper"> <action name="action_setWallpaper">
<property name="icon">
<iconset theme="computer"/>
</property>
<property name="text"> <property name="text">
<string>设为壁纸</string> <string>设为壁纸</string>
</property> </property>
</action> </action>
<action name="action_help"> <action name="action_help">
<property name="icon">
<iconset theme="help-contents"/>
</property>
<property name="text"> <property name="text">
<string>帮助</string> <string>帮助</string>
</property> </property>
@ -244,16 +287,25 @@
</property> </property>
</action> </action>
<action name="action_changelog"> <action name="action_changelog">
<property name="icon">
<iconset theme="help-faq"/>
</property>
<property name="text"> <property name="text">
<string>更新日志</string> <string>更新日志</string>
</property> </property>
</action> </action>
<action name="action_about"> <action name="action_about">
<property name="icon">
<iconset theme="help-about"/>
</property>
<property name="text"> <property name="text">
<string>关于</string> <string>关于</string>
</property> </property>
</action> </action>
<action name="action_new"> <action name="action_new">
<property name="icon">
<iconset theme="document-new"/>
</property>
<property name="text"> <property name="text">
<string>新建</string> <string>新建</string>
</property> </property>
@ -574,6 +626,14 @@
<string>颜色透明</string> <string>颜色透明</string>
</property> </property>
</action> </action>
<action name="action_mosaic">
<property name="text">
<string>马赛克</string>
</property>
<property name="shortcut">
<string>Ctrl+M</string>
</property>
</action>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<resources> <resources>