当前位置:网站首页>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();边栏推荐
- How to fix Error: Failed to download metadata for repo ‘appstream‘: Cannot prepare internal mirrorli
- Fault: KDC warning log for id29
- VerilogA——动态比较器
- RPC和RMI
- Failure: unable to log in to "taxpayer equity platform"
- MySQL learning notes
- National Defense University project summary
- Games101 Lecture 10 geometry 1 Notes
- Easy to understand TCP four waves (multi picture explanation)
- Mongodb paging method
猜你喜欢

idea使用

The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves

Configuring the flutter development environment

Service grid ASM year end summary: how do end users use the service grid?

RPC和RMI

把多个ROC曲线画在一张图上

Rich material libraries make modeling easy and efficient for developers

融入STEAM教育的劳动技能课程

Easy to understand TCP four waves (multi picture explanation)

Chapter V online logic analyzer signaltap
随机推荐
融入STEAM教育的劳动技能课程
Where is the Gcov symbol- Where are the gcov symbols?
I would like to ask what securities dealers recommend? Is it safe to open an account online?
Li Kou daily question - day 30 -1281 Difference of sum of bit product of integer
Aging design guide for applets
Pointer from beginner to advanced (2)
Sourcetree remote red exclamation point
json tobean
Are there too many programmers in China at present?
Is there any difference between a=a+b and a+=b?
What are the uses of final?
配置Flutter开发环境
Fault: administrator account cannot be selected for login
MySQL learning notes
Honeypot based on MySQL load data local INFILE
Fault: display Storport driver out of date in component health
try anbox (by quqi99)
What are the uses of wireless pressure collectors?
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
centos下配置mysql 5.7 和 8