C++ QImage 和 QPixmap 有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10307860/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between QImage and QPixmap?
提问by Mr.Tu
I do not understand what is the difference between QImage and QPixmap, they seem to offer the same functionality. When should I use a QImage and when should I use a QPixmap?
我不明白 QImage 和 QPixmap 之间有什么区别,它们似乎提供相同的功能。什么时候应该使用 QImage,什么时候应该使用 QPixmap?
采纳答案by karlphillip
Easilly answered by reading the docs on QImageand QPixmap:
The QPixmapclass is an off-screenimage representation that can be used as a paint device.
The QImageclass provides a hardware-independent image representation that allows direct access to the pixel data, and can be used as a paint device.
所述的QPixmap类是一个离屏,可用于作为涂料设备图像表示。
所述QImage的类提供独立于硬件的图像表示,其允许像素数据的直接访问,并且可以被用作涂料设备。
Edit:Also, from @Dave's answer:
编辑:另外,来自@Dave 的回答:
You can't manipulate a QPixmap outside the GUI-thread, but QImage has no such restriction.
您不能在 GUI 线程之外操作 QPixmap,但 QImage 没有这样的限制。
And from @Arnold:
来自@Arnold:
Here's a short summary that usually (not always) applies:
- If you plan to manipulate an image, modify it, change pixels on it, etc., use a QImage.
- If you plan to draw the same image more than once on the screen, convert it to a QPixmap.
这是一个通常(并非总是)适用的简短摘要:
- 如果您打算操作图像、修改图像、更改其上的像素等,请使用 QImage。
- 如果您打算在屏幕上多次绘制相同的图像,请将其转换为 QPixmap。
回答by Arnold Spence
There is a nice series of articles at Qt Labs that explains a lot about the Qt graphics system. This articlein particular has a section on QImage
vs. QPixmap
.
Qt Labs 有一系列很好的文章,其中解释了很多关于 Qt 图形系统的内容。这篇文章特别有一节是关于QImage
vs. 的QPixmap
。
Here's a short summary that usually (not always) applies:
这是一个通常(并非总是)适用的简短摘要:
- If you plan to manipulate an image, modify it, change pixels on it, etc., use a
QImage
. - If you plan to draw the same image more than once on the screen, convert it to a
QPixmap
.
- 如果您打算操作图像、修改图像、更改图像上的像素等,请使用
QImage
. - 如果您打算在屏幕上多次绘制相同的图像,请将其转换为
QPixmap
.
回答by Dave Mateer
One important difference is that you cannot create or manipulate a QPixmap
on anything but the main GUI thread. You can, however, create and manipulate QImage
instances on background threads and then convert them after passing them back to the GUI thread.
一个重要的区别是,QPixmap
除了主 GUI 线程之外,您不能在任何东西上创建或操作 a 。但是,您可以QImage
在后台线程上创建和操作实例,然后在将它们传递回 GUI 线程后转换它们。
回答by iksess
Important in industrial environments:
在工业环境中很重要:
The QPixmap is stored on the video card doing the display. Not the QImage.
QPixmap 存储在进行显示的视频卡上。不是 QImage。
So if you have a server running the application, and a client station doing the display, it is very significant in term of network usage.
因此,如果您有一台运行该应用程序的服务器,以及一个执行显示的客户端工作站,那么就网络使用而言,这是非常重要的。
With a Pixmap, a Redraw consists in sending only the order to redraw (a few bytes) over the network.
使用像素图,重绘包括仅通过网络发送重绘的顺序(几个字节)。
With a QImage, it consists in sending the whole image (around a few MB).
使用 QImage,它包括发送整个图像(大约几 MB)。
回答by Mohammad Kanan
QPixmapis an "image object" whose
pixel
representation are of no consequence in your code, Thus QPixmap is designed and optimized for rendering imageson display screen, it is stored on the XServer when using X11, thus drawing QPixmap on XWindow is much fasterthan drawing QImages, as the data is already on the server, and ready to use.When to use QPixmap: If you just want to draw an existing image (icon .. background .. etc) especially repeatedly, then use QPixmap.
QImageis an "array of pixels in memory" of the clientcode, QImage is designed and optimized for I/O, and for direct pixel access and manipulation.
When to use QImage: If you want to draw, with Qpaint, or manipulate an image pixels.
QBitmapis only a convenient QPixmap subclass ensuring a depth of 1, its a monochrome (1-bit depth) pixmap. Just like QPixmap , QBitmap is optimized for use of implicit data sharing.
- QPictureis a paint device that records and replays QPainter commands -- your drawing --
QPixmap是一个“图像对象”,其
pixel
表示在您的代码中无关紧要,因此 QPixmap 是为在显示屏上渲染图像而设计和优化的,使用 X11 时它存储在 XServer 上,因此在 XWindow 上绘制 QPixmap比绘图快得多QImages,因为数据已经在服务器上,可以使用了。何时使用 QPixmap:如果您只想重复绘制现有图像(图标 .. 背景 .. 等),请使用 QPixmap。
QImage是客户端代码的“内存中的像素数组” ,QImage 是为 I/O 以及直接像素访问和操作而设计和优化的。
何时使用 QImage:如果您想使用 Qpaint 进行绘制或操作图像像素。
QBitmap只是一个方便的 QPixmap 子类,确保深度为 1,它是一个单色(1 位深度)像素图。就像 QPixmap 一样, QBitmap 针对隐式数据共享的使用进行了优化。
- QPicture是一个绘画设备,它记录和重放 QPainter 命令——你的绘图——