QPaintDevice 绘图设备
1 QPixmap QImage Qbitmap(黑白色) QPicture QWidget
2 QPixmap 对不同平台做了显示优化 fill(填充颜色) QPainter paintere(&pic) 画家往设备上画 画完保存 save("路径")
3 QImage 可以对像素进行访问,和 QPixmap 差不多 对像素进行修改 img.setPixel();
4 Qpicture 记录和重现绘图指令。save 的时候可以上任意后缀名称 重现利用画家 painter.drawPicture();
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = nullptr);
~Widget();
protected:
void paintEvent(QPaintEvent * even);
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
widght.cpp
#include "widget.h"
#include "ui_widget.h"
#include
#include
#include
#include
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
//绘画设备专门为为平台做显示优化的
QPixmap pixmap(300,300);
pixmap.fill(Qt::white);//填充颜色
QPainter painter(&pixmap);
painter.setPen(QPen(Qt::green)); //设置绿色
//在设备上画圆
painter.drawEllipse(QPoint(100,100),100,100);//在点100,100 的位置画圆
pixmap.save("/Users/libin/qtProject/painterDraw/pix.png");
//////图片//////Qimag
QImage imag(300,300,QImage::Format\_ARGB32);
QPainter painter2(&imag);
painter2.setPen(QPen(Qt::red));
painter2.drawEllipse(QPoint(150,150),100,100);
imag.save("/Users/libin/qtProject/painterDraw/imag.png");
////QPictrue///////////绘图设备可以记录和重现绘图指令
QPicture picture;
QPainter painter4;
painter4.setPen(QPen(Qt::red));
painter4.begin(&picture); //开始往设备上画
painter4.drawEllipse(QPoint(20,20),200,200);
painter4.end();//结束
picture.save("/Users/libin/qtProject/paintDevice/pic.zt");
}
void Widget::paintEvent(QPaintEvent *even){
QImage img;
img.load(":/mm.png");
QPainter painter3(this);
for(int i =0;i<200;++i){
for(int j = 0;j<200;++j){
QRgb rbg = qRgb(255,i,j);
img.setPixel(i,j,rbg);
}
}
painter3.drawImage(0,0,img);
//读取画笔指令
QPainter q5(this);
QPicture picture3;
picture3.load("/Users/libin/qtProject/paintDevice/pic.zt");
q5.drawPicture(0,0,picture3);
}
Widget::~Widget()
{
delete ui;
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章