当前位置:网站首页>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
边栏推荐
- What is a gateway
- Database Navigator 使用默认MySQL连接提示:The server time zone value ‘Öйú±ê׼ʱ¼ä’ is unrecognized or repres
- 《通用数据保护条例》(GDPR)系列解读三:欧洲子公司如何向国内母公司回传数据?
- 一文详解头部位姿估计【收藏好文】
- 5-minute NLP: text to text transfer transformer (T5) unified text to text task model
- How much does software testing help reduce program bugs?
- Why is the premise of hash% length = = hash & (length-1) that length is the nth power of 2
- Intelligent multi line elastic cloud adds independent IP address. How to realize multi line function?
- How imeu is associated with imcu (IM 5.5)
- PSCP basic usage
猜你喜欢
How to expand the capacity of the server in the 100 million level traffic architecture? Well written!
Qt一个进程运行另一个进程
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
WIN10 启动后花屏
The maximum number of remote desktop servers has been exceeded
科创人·派拉软件CEO谭翔:零信任本质是数字安全,To B也要深研用户心智
Worder font page font comparison table
亿级流量架构,服务器如何扩容?写得太好了!
Relu function of activation function
如果你是一个Golang面试官,你会问哪些问题?
随机推荐
Chapter 4 specifies the attribute of the inmemory column on the no inmemory table for im enabled filling objects: examples (Part IV of im-4.4)
万事有你 未来可期 | ONES 2022校园招聘正式开启
远程访问家里的树莓派(上)
Use kettle to copy records to and get records from results
编程辅助工具推荐:图片工具snipaste
How the database fills in IM expressions (IM 5.4)
IDEA 代码质量规范插件SonarLint
A detailed explanation of head pose estimation [collection of good articles]
C set Logo Icon and shortcut icon
On using go language to create websocket service
Lesson 24 analysis of classical problems
什么是网关
Windows2008系统如何切换PHP版本
5个免费音频素材网站,建议收藏
IDEA设置版权信息
欣旺达宣布电池产品涨价 此前获“蔚小理”投资超10亿
Idea setting copyright information
User interface and im expression (IM 5.6)
Recommended programming AIDS: picture tool snipaste
The fourth chapter is to enable the filling object of IM and enable ADO for im column storage (IM 4.8)