Qt绘图2
2016-01-25 00:04
323 查看
Qt的绘图设备只能是QPaintDevice的子类,在Qt5中,继承自它的有:QWidget、QImage、QPixmap、QGLFramebufferObject、QPicture、QPrinter,还有继承自Qwidget的QGLWidget。
简单来说,QPixmap专门为图像在屏幕上的显示做了优化,QBitmap是QPixmap的子类,但是只能显示黑白图片,可以通过QPixmap的isQBitmap() 来确定是否该QPixmap是QBitmap。QImage专门为图像的像素级访问做了优化。QPicture则可以记录和重现QPainter的各条指令。
QPixmap继承了QPaintDevice,所以可以使用QPainter在上面绘图。QPixmap也可以接受一个字符串作为文件的路径来显示图片。使用QPainter:: drawPixmap()可以把文件绘制到一个QLabel、或者继承了QAbstractButton(如:QPushButton、QToolButton)上面。QLabel有一个pixmap属性,QAbstractButton有一个icon属性。QPixmap可以使用传值的方式,因为Qt已经为它实现了隐式数据共享。
QBitmap继承自QPixmap,但是QBitmap的色深为1,也就是每个像素用一个二进制位表示。可以保证绘制的图像为黑白两色,且占用内存很小。The QBitmap class is a monochrome off-screen paint device used mainly for creating custom QCursor and QBrush objects, constructing QRegion objects, and for setting masks for pixmaps and widgets.
QImage最大特色在于可以对像素进行快速操作,因此比较适合用于图像处理。The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.
QPicture类是用于记录和重播QPainter命令的类,它以一个独立于平台的格式序列化QPainter的命令到一个IO device中,有时候他们也可以作为meta-files. QPicture使用了二进制格式的属性,不像Windows上的很多本地的图像格式,Qt picture对于他们的内容没有限制。任何可以被绘制到widget 或者 pixmap东西(如字体、pixmap、region、transformed graphics等)都可以存储到一个图像中。
QPicture是与分辨率无关的,这意味着QPicture可以在不同设备上看起来都一样。举个例子吧:
你会发现有一个drawing.pic文件保存在本地了,它记录了从painter.begin()到painter.end()之间的对于painter的操作。
简单来说,QPixmap专门为图像在屏幕上的显示做了优化,QBitmap是QPixmap的子类,但是只能显示黑白图片,可以通过QPixmap的isQBitmap() 来确定是否该QPixmap是QBitmap。QImage专门为图像的像素级访问做了优化。QPicture则可以记录和重现QPainter的各条指令。
QPixmap继承了QPaintDevice,所以可以使用QPainter在上面绘图。QPixmap也可以接受一个字符串作为文件的路径来显示图片。使用QPainter:: drawPixmap()可以把文件绘制到一个QLabel、或者继承了QAbstractButton(如:QPushButton、QToolButton)上面。QLabel有一个pixmap属性,QAbstractButton有一个icon属性。QPixmap可以使用传值的方式,因为Qt已经为它实现了隐式数据共享。
QBitmap继承自QPixmap,但是QBitmap的色深为1,也就是每个像素用一个二进制位表示。可以保证绘制的图像为黑白两色,且占用内存很小。The QBitmap class is a monochrome off-screen paint device used mainly for creating custom QCursor and QBrush objects, constructing QRegion objects, and for setting masks for pixmaps and widgets.
QImage最大特色在于可以对像素进行快速操作,因此比较适合用于图像处理。The QImage class provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.
QPicture类是用于记录和重播QPainter命令的类,它以一个独立于平台的格式序列化QPainter的命令到一个IO device中,有时候他们也可以作为meta-files. QPicture使用了二进制格式的属性,不像Windows上的很多本地的图像格式,Qt picture对于他们的内容没有限制。任何可以被绘制到widget 或者 pixmap东西(如字体、pixmap、region、transformed graphics等)都可以存储到一个图像中。
QPicture是与分辨率无关的,这意味着QPicture可以在不同设备上看起来都一样。举个例子吧:
void PaintWidget::paintEvent(QPaintEvent *) { 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 myPaint(); } void PaintWidget::myPaint() { QPicture picture; picture.load("drawing.pic"); // load picture QPainter painter; painter.begin(this); // paint in myImage painter.drawPicture(0, 0, picture); // draw the picture at (0,0) painter.end(); }
你会发现有一个drawing.pic文件保存在本地了,它记录了从painter.begin()到painter.end()之间的对于painter的操作。
相关文章推荐
- Ubuntu上安装Qt5
- centos6.3 INSTALL QT5.0 ERROR
- Qt5 Release 发布
- VMware7.1.4 + Centos6.5 + QT5.2.1 for android 开发环境配置
- Qt + opencv +mac
- QT5 QList<QImage> 中后面数据将前面数据覆盖问题的解决方案
- [Qt]Qt5.3.0+VS2013+Win32平台搭建
- 使用VS2013_X68;PCL1.7.2;QT5;VTK6.2实现qt显示PCL
- 欢迎使用CSDN-markdown编辑器
- 用Qt自动绘制路口
- windows7下vs2012+qwt6.1+qt5.3.1的配置注意问题。
- Ubuntu 12.04安装Qt 5.3后开发出现的问题
- Win7 Qt5.4.1+VS2013编译Oracle驱动,连接Oracle数据库
- QT creator 3.4.1配置arm交叉编译环境(QT5.4.2)
- build qgroundcontrol source code
- Qwt安装后出现于QtCreator不兼容的问题:解决方法
- Location解密修正版
- 虾米音乐解析器Qt版
- 【QT5】【错误码】查找工具
- ubuntu-kylin14.10下Qt5.3.2配置