当前位置:网站首页>QT draw image
QT draw image
2022-04-23 12:15:00 【MechMaster】
Qt The plot
1. Routine code
void Widget::paintEvent(QPaintEvent *event)
{
QPainter painter;
// draw 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();
// draw 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();
// draw 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();
// draw 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();
// stay widget Draw on the part
painter.begin(this);
painter.drawImage(50,20,image);
painter.drawPixmap(200,20,pix);
painter.drawPixmap(50,170,bit);
painter.drawPicture(200,170,picture);
}
2. Four common drawing devices
2.1 QImage
- QImage Mainly used for I/O Handle , It's right I/O Processing operations are optimized , And it can be used to directly access and manipulate pixels ;
2.2 QPixmap
- QPixmap It's mainly used to display images on the screen , It optimizes which image is displayed on the screen ;
2.3 QBitmap
- QBitmap yes QPixmap Subclasses of , It's used to process colors with a depth of 1 Image , That is, only black and white can be displayed ;
2.4 QPicture
- QPicture Used to record and replay QPainter command .
3. Compound mode
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://yzsam.com/2022/04/202204231210423968.html
边栏推荐
- 第四章 为IM 启用填充对象之启用和禁用列(IM-4.3 第三部分)
- Recommended programming AIDS: picture tool snipaste
- 万事有你 未来可期 | ONES 2022校园招聘正式开启
- C# F23.StringSimilarity库 字符串重复度、文本相似度、防抄袭
- c# 设置logo图标和快捷方式的图标
- 1.Electron开发环境搭建
- The fourth chapter is the enable and disable columns of IM enabled fill objects (Part III of im-4.3)
- Basic software testing Day2 - Case Execution
- 一个平面设计师的异想世界|ONES 人物
- 论文解读(CGC)《CGC: Contrastive Graph Clustering for Community Detection and Tracking》
猜你喜欢
Idea setting copyright information
PSCP basic usage
Tan Xiang, CEO of Kechuang · Pera software: the essence of zero trust is digital security. To B should also deeply study the user's mind
IFLYTEK's revenue in 2021 was 18.3 billion yuan: a year-on-year increase of 41% and a net profit of 1.556 billion yuan
Idea database navigator plug-in
激活函数之relu函数
九十八、freemarker框架报错 s.e.ErrorMvcAutoConfiguration$StaticView : Cannot render error page for request
Step function of activation function
程序员如何用130行代码敲定核酸统计
运行报错:找不到或无法加载主类 com.xxx.Application
随机推荐
力扣-1137.第N个泰波那契数
Qt重绘事件与剪切
第五章 使用In-Memory表达式优化查询(IM 5.1)
Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
IDEA 代码质量规范插件SonarLint
IM 体系结构:CPU架构:SIMD向量处理(IM-2.3)
Array---
The fourth chapter is to enable the filling object of IM and enable ADO for im column storage (IM 4.8)
Lesson 26 static member functions of classes
On using go language to create websocket service
IM表达式的目的(IM 5.2)
使用连接组优化连接 (IM 6)
Win10 splash screen after startup
什么是网关
远程桌面之终端服务器超出了最大允许连接数解决
Windows11 安装MySQL服务 提示:Install/Remove of the Service Denied
1.Electron开发环境搭建
Optimize connections using connection groups (IM 6)
软银愿景基金进军Web3安全行业 领投CertiK 6000万美元新一轮投资
Qt进程间通信