当前位置:网站首页>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
边栏推荐
- Optimize connections using connection groups (IM 6)
- How to expand the capacity of the server in the 100 million level traffic architecture? Well written!
- Symmetric encryption, certificate encryption
- The fourth chapter is about enabling and disabling the im column storage of table space for im enabled filling objects (IM 4.5)
- On lambda powertools typescript
- 5个免费音频素材网站,建议收藏
- 一文详解头部位姿估计【收藏好文】
- 面了一圈,整理了这套面试题。。
- Redis learning 5 - high concurrency distributed lock practice
- 同态加密技术学习
猜你喜欢
电脑系统卡如何解决?
CGC: contractual graph clustering for community detection and tracking
Recommended programming AIDS: picture tool snipaste
Worder font page font comparison table
Metalama简介4.使用Fabric操作项目或命名空间
Step function of activation function
程序员如何用130行代码敲定核酸统计
Sofa weekly | excellent Committee of the year, contributor of this week, QA of this week
IDEA 中 .properties文件的中文显示乱码问题的解决办法
Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
随机推荐
IM 体系结构:CPU架构:SIMD向量处理(IM-2.3)
Interpretation 3 of gdpr series: how do European subsidiaries return data to domestic parent companies?
抓包整理————tcp 协议[八]
Chapter 4: enable and disable im column storage for materialized view (IM 4.6)
【Redis 系列】redis 学习十三,Redis 常问简单面试题
IM表达式如何工作(5.3)
Debug Jest test cases in VSCode, debug Jest test cases in VSCode, middle note basedir=$(dirname "$" (echo "$0" sed -e -e, s, \ \, / "-e").
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
How to solve the computer system card?
编程辅助工具推荐:图片工具snipaste
In idea Solution to the problem of garbled code in Chinese display of properties file
C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
在 VSCode 中调试 Jest 的测试用例,VSCode调试Jest测试用例报错basedir=$(dirname “$(echo “$0“ | sed -e ‘s,\\,/,g‘)“)解决
什么是网关
一文详解头部位姿估计【收藏好文】
5分钟NLP:Text-To-Text Transfer Transformer (T5)统一的文本到文本任务模型
31岁才转行程序员,目前34了,我来说说我的经历和一些感受吧...
Force buckle - 70 climb stairs
How to switch PHP version in Windows 2008 system
2022 love analysis · panoramic report of industrial Internet manufacturers