資源簡(jiǎn)介
QT繪圖是學(xué)習(xí)QT必不可少的技能,以下是畫(huà)圖的簡(jiǎn)單實(shí)現(xiàn),僅供需要的人士參考。
代碼片段和文件信息
#include?“Form.h“
Form::Form(QWidget?*parent):QWidget(parent)
{???oldx=0;oldy=0;//用來(lái)記錄前一坐標(biāo)(xy)
????this->setAttribute(Qt::WA_NoBackground);
????bDrawing=false;
????curShape=Ellipse;
????this->resize(800600);//初始化兩個(gè)緩沖區(qū)
????bufferImage=QImage(this->width()this->height()
???????????????????????QImage::Format_ARGB32_Premultiplied);//bufferImage用來(lái)存儲(chǔ)最終的圖形
????bufferImage.fill(qRgb(255255255));
????tempImage=QImage(this->width()this->height()
?????????????????????QImage::Format_ARGB32_Premultiplied);//tempImage是臨時(shí)緩沖區(qū)
}
void?Form::setImage(QString?fileName)//打開(kāi)文件
{
????this->clear();
????bufferImage.load(fileName);
????this->update();
}
void?Form::saveImage(QString?fileName)//保存文件
{
????QImage?saveFile(fileName“bmp“);
????saveFile=QImage(this->width()thi
評(píng)論
共有 條評(píng)論