- 绘图设备:
- QPixmap:针对屏幕进行优化,和平台相关,不能对图片进行修改
- QImage:和平台无关,可以对图片进行修改,在线程中绘图
- QPicture:将绘图状态保存为一个二进制文件
用法相同,但作用有区别
#ifndef MAINWINDOW_H |
#include "mainwindow.h" |
- 保存图片
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPainter>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
//绘图设备,400*300
QPixmap pixmap(400,300);
QPainter p(&pixmap);
//填充白色
p.fillRect(0,0,400,300,QBrush(Qt::white));
p.drawPixmap(0,0,80,80,QPixmap("C:/Users/lxm/Pictures/3e40d65390723ce873e88385b4d57bff.jpeg"));
//保存图片
pixmap.save("../pixmap.png");
}
MainWindow::~MainWindow()
{
delete ui;
}
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.