当前位置:网站首页>Qt 处理图像数据的类区别(QPixmap、QImage、QPicture)
Qt 处理图像数据的类区别(QPixmap、QImage、QPicture)
2022-06-29 06:37:00 【Mr.codeee】
1.简介
Qt提供了处理图像数据的类:QImage, QPixmap和QPicture。
- QImage是为I/O和直接像素访问和操作而设计和优化的
- QPixmap是为在屏幕上显示图像而设计和优化的。
- QPicture类是一个记录和回放QPainter命令的绘制设备。
2.QImage
QImage类提供了一个独立于硬件的图像表示,它允许直接访问像素数据,并且可以用作绘制设备;适合加载大图片;可以在线程中绘图,可以优化UI响应时间。绘制图片出来的效果和平台无关,QImage上绘图比较快,但显示它则比较慢。
绘制图片:
QImage image;
image.load("./test.png");
QPainter painter(this);
painter.drawImage(0,0,image);绘制大图:可以用QImage先把图片加载进来,改变大小,转成QPixmap。
QImage image;
image.load("./big.png");
QPixmap pixmap = QPixmap::fromImage(image.scaled(size(),Qt::KeepAspectRatio));
QPainter painter(this);
painter.drawPixmap(0,0,pixmap);;2.QPixmap
QPixmap绘图依赖硬件,QPixmap的设计本来就是用来加速显示,用paint绘图时用QPixmap会比其他类的效果好很多。一般小图片用QPixmap加载,和平台相关(在不同的平台可能绘制出的效果不一样)。QPixmap上绘图比较慢,但显示它则比较快。
QLabel加载图片:
ui->lbImg->setPixmap(QPixmap("test.jpg"));QPixmap与QImage互相转换
QImage image = pixmap.toImage();
QPixmap pixmap = QPixmap::fromImage(image);3.QPicture
记录和回放QPainter的绘图指令
- begin() 开始在QPicture上绘图
- end() 结束在QPicture上绘图
- save() 保存操作为.pic文件
- load() 加载.pic文件
示例:画圆,保存图片
QPicture picture;
QPainter painter;
painter.begin(&picture); // paint in picture
painter.drawEllipse(10,20, 80,70); // draw an ellipse
painter.end(); // painting done
picture.save("drawing.pic"); // save picture示例:加载图片
QPicture picture;
QPainter painter;
picture.load("drawing.pic");
painter.begin(this);
painter.drawPicture(0,0,picture);
painter.end();边栏推荐
- Single application and microservice application
- C language pointer to function
- Configuring the flutter development environment
- Yyds dry goods inventory meituan's two-sided experience, and finally there was a surprise?
- Json对象和Json字符串的区别
- 分享 10 个 JS Promise 相关的面试题
- Li Kou daily question - day 30 -1523 Number of bit 1
- Draw smooth curves - methods needed - drawing smooth curves - methods needed
- Delete tag
- Failure: unable to log in to "taxpayer equity platform"
猜你喜欢

分享 10 个 JS Promise 相关的面试题

2022.02.15 - SX10-31. House raiding III

Are there too many programmers in China at present?

Move disassembly of exclusive delivery of script (the first time)

json tobean

json tobean

Fault: NetBt log for id4321

How does schedulerx help users solve distributed task scheduling problems?

jetson tx2

Small program large screen adaptation Guide
随机推荐
Vite quick start
Aging design guide for applets
About DDNS
Chapter IV introduction to FPGA development platform
Mongodb sort function
层次分析法
Li Kou daily question - day 30 -594 Longest harmonic subsequence
QT (x): control operation
2022.02.14
Rich material libraries make modeling easy and efficient for developers
package. Are you familiar with all configuration items and their usage of JSON
Are there too many programmers in China at present?
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
Analysis comp122 the Caesar cipher
QT (x): packaging and deployment
VerilogA - dynamic comparator
Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
MySQL add / delete / modify query SQL statement exercise yyds dry goods inventory
json tobean
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]