照片压缩工具-comicstudio中文版下载

drawimage
2023年4月2日发(作者:instagram怎么保存图片)

QT多线程绘图

绘画类,发送⾃动⽣成的Image图像。

#ifndefMYTHREAD_H

#defineMYTHREAD_H

#include

#include

classmyThread:publicQObject

{

Q_OBJECT

public:

explicitmyThread(QObject*parent=0);

signals:

voidupdatImage(QImage);

publicslots:

voiddrawImage();

};

#endif//MYTHREAD_H

#include"mythread.h"

#include

myThread::myThread(QObject*parent):QObject(parent)

{

}

voidmyThread::drawImage()

{

QImageimage(600,600,QImage::Format_ARGB32);

QPainterp(&image);

QPenpen;

th(5);

(pen);

QBrushbrush;

le(Qt::SolidPattern);

or(Qt::red);

sh(brush);

QPointa[]=

{

QPoint(qrand()%500,qrand()%500),

QPoint(qrand()%500,qrand()%500),

QPoint(qrand()%500,qrand()%500),

QPoint(qrand()%500,qrand()%500),

QPoint(qrand()%500,qrand()%500)

};

lygon(a,5);

emitupdatImage(image);

}

多线程⽅法调⽤并绘画

#include"widget.h"

#include"ui_widget.h"

#include"mythread.h"

#include

#include

Widget::Widget(QWidget*parent):

QWidget(parent),

ui(newUi::Widget)

{

ui->setupUi(this);

myT=newmyThread;

thread=newQThread(this);

myT->moveToThread(thread);

thread->start();

connect(ui->pushButton,SIGNAL(pressed()),myT,SLOT(drawImage()));

connect(myT,&myThread::updatImage,this,&Widget::getImage);

connect(this,SIGNAL(destroyed(QObject*)),this,SLOT(dealClose(QObject*)));

}

voidWidget::dealClose(QObject*sd)

{

thread->quit();

thread->wait();

deletemyT;

}

Widget::~Widget()

{

deleteui;

}

voidWidget::getImage(QImageimg)

{

this->image=img;

update();

}

voidWidget::paintEvent(QPaintEvent*)

{

QPainterp(this);//

age(50,50,image);

}

点击button随机⽣成五点⼏何图形。

更多推荐

drawimage