当前位置:网站首页>Qt绘制图像
Qt绘制图像
2022-04-23 12:10:00 【MechMaster】
1. 例程代码
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter;
//绘制image
QImage image(100,100,QImage::Format_ARGB32);
painter.begin(&image);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QImage"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制pixmap
QPixmap pix(100,100);
painter.begin(&pix);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QPixmap"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制bitmap
QBitmap bit(100,100);
painter.begin(&bit);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QBitmap"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//绘制picture
QPicture picture;
painter.begin(&picture);
painter.setPen(QPen(Qt::red,3));
painter.setBrush(Qt::yellow);
painter.drawRect(10,10,60,60);
painter.drawText(10,10,60,60,Qt::AlignCenter,tr("QPicture"));
painter.setBrush(QColor(0,0,0,100));
painter.drawRect(50,50,40,40);
painter.end();
//在widget部件上进行绘制
painter.begin(this);
painter.drawImage(50,20,image);
painter.drawPixmap(200,20,pix);
painter.drawPixmap(50,170,bit);
painter.drawPicture(200,170,picture);
}
2. 四个常用的绘图设备
2.1 QImage
- QImage主要用来进行I/O处理,它对I/O处理操作进行了优化,而且可以用来直接访问和操作像素;
2.2 QPixmap
- QPixmap主要用来在屏幕上显示图像,它对在屏幕上显示图像那个进行了优化;
2.3 QBitmap
- QBitmap 是 QPixmap 的子类,用来处理颜色深度为1的图像,即只能显示黑白两种颜色;
2.4 QPicture
- QPicture用来记录并重演QPainter命令。
3. 复合模式
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter;
QImage image(400,300,QImage::Format_ARGB32_Premultiplied);
painter.begin(&image);
painter.setBrush(Qt::green);
painter.drawRect(100,50,200,200);
painter.setBrush(QColor(0,0,255,15));
painter.drawRect(50,0,100,100);
painter.setCompositionMode(QPainter::CompositionMode_SourceIn);
painter.drawRect(250,0,100,100);
painter.setCompositionMode(QPainter::CompositionMode_DestinationOver);
painter.drawRect(50,200,100,100);
painter.setCompositionMode(QPainter::CompositionMode_Xor);
painter.drawRect(250,200,100,100);
painter.end();
painter.begin(this);
painter.drawImage(0,0,image);
}
版权声明
本文为[MechMaster]所创,转载请带上原文链接,感谢
https://liuhui.blog.csdn.net/article/details/124264238
边栏推荐
- IDEA 代码质量规范插件SonarLint
- Pagoda panel command line help tutorial (including resetting password)
- On using go language to create websocket service
- AI 视频云 VS 窄带高清,谁是视频时代的宠儿
- Tensorflow common functions
- 网络信息安全之零信任
- Worder font page font comparison table
- Recommended programming AIDS: picture tool snipaste
- 远程桌面之终端服务器超出了最大允许连接数解决
- SQL 练习(一)
猜你喜欢
Resolution due to AMD not found_ ags_ x64. DLL, unable to continue code execution. Reinstallation of the program may solve this problem, Forza horizon 5
远程访问家里的树莓派(上)
力扣-70.爬楼梯
抓包整理————tcp 协议[八]
Fastjson 2 is coming, the performance continues to improve, and it can fight for another ten years
After a circle, I sorted out this set of interview questions..
Introduction to metalama 4 Use fabric to manipulate items or namespaces
Idea setting copyright information
2022 love analysis · panoramic report of industrial Internet manufacturers
IDEA 代码格式化插件Save Actions
随机推荐
Force buckle - 70 climb stairs
IMEU如何与IMCU相关联(IM 5.5)
Castle.DynamicProxy实现事务单元控制
On lambda powertools typescript
智能多线弹性云增加独立的IP地址,如何实现多线功能?
ImportError: libX11. so. 6: cannot open shared object file: No such file or directory
PSCP 基本使用
Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
外包干了五年,废了...
宝塔面板命令行帮助教程(包含重置密码)
How much does software testing help reduce program bugs?
The listing of saiweidian Technology Innovation Board broke: a decrease of 26% and the market value of the company was 4.4 billion
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
Idea code quality specification plug-in sonarlint
第四章 为IM 启用填充对象之为IM列存储启用ADO(IM 4.8)
oh-my-lotto
魔域来了H5游戏详细图文架设教程
The fourth chapter is to enable the filling object of IM and enable ADO for im column storage (IM 4.8)
如果你是一个Golang面试官,你会问哪些问题?
第二十四课 经典问题解析