What is the difference between QImage and QPixmap?
Asked Answered
A

5

102

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?

Anam answered 25/4, 2012 at 0:30 Comment(4)
I'm not sure if I understand your question, but I thought it was pretty clear in the documentation: "QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen." doc.qt.nokia.com/latest/qpixmap.html#detailsWaxwork
yeah! i had find it out,but not understand well, for example, optimized for I/O and optimized for showing, it is difference a picutre showed on difference platform ? ..Can you help me make a step to explain.. thank you..Anam
I'm still not 100% sure I know what you mean, but if you're using QWidgets, you can display it in a QLabel. If you're using QGraphicsView, you can display it in a QGraphicsPixmapItem. If you're using QML the Image element will handle everything for you.Waxwork
Let me put it another way, what is the Engine, what is its work? when to use it?Anam
W
66

Easilly answered by reading the docs on QImage and QPixmap:

The QPixmap class is an off-screen image representation that can be used as a paint device.

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.

Edit: Also, from @Dave's answer:

You can't manipulate a QPixmap outside the GUI-thread, but QImage has no such restriction.

And from @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.
Walling answered 25/4, 2012 at 12:37 Comment(4)
thanks for your help... what is general process that QPixmpa and QImage load a picture.. what is it in memory.. thank you..Anam
I'm not sure what you are trying to do, but in this question I demonstrate how to load YV12 data from the disk, convert to RGB using a GLSL fragment shader, and then display it on the screen inside a QImage. I guess I could point you to right direction if you were more clear about what you are trying to accomplish.Walling
Does this really answer anything?Emmettemmey
Just copying documentation and others' answers doesn't make sense.Orthodontia
M
55

There is a nice series of articles at Qt Labs that explains a lot about the Qt graphics system. This article in particular has a section on 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.
Methodius answered 25/4, 2012 at 4:28 Comment(3)
thank you. This passage tell us: there are two different way to load a picture, raster and OpenGL ? is right?Anam
I don't quite understand the question. Neither "raster" nor "OpenGL" specifically represent ways to load a picture.Methodius
Does QImage's "manipulating and modifying" includes it being saves as an image file? If I start out with a QImage object, which one is faster when saving it as an image file?Solidago
H
38

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.

Hadj answered 25/4, 2012 at 12:22 Comment(0)
I
24

Important in industrial environments:

The QPixmap is stored on the video card doing the display. Not the 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).

Irs answered 6/6, 2013 at 8:19 Comment(2)
"With a Pixmap, a Redraw consists in sending only the order to redraw (a few bytes) over the network.".. That is misleading. The video-memory is limited too, so what if it does not have the data?Piero
@Nawaz: Of course, the image has to be sent at least once, over the network, and the memory is limited. But as long as it is in video memory (as long as it is displayed, I imagine), the redraw orders will be executed without re-sending it. When something is drawn in front of the image, for example. We observed that on our network data flow. In 2012 !... :PIrs
E
24
  • QPixmap is an "image object" whose pixel representation are of no consequence in your code, Thus QPixmap is designed and optimized for rendering images on display screen, it is stored on the XServer when using X11, thus drawing QPixmap on XWindow is much faster than 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.

  • QImage is an "array of pixels in memory" of the client code, 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.

  • QBitmap is 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.

  • QPicture is a paint device that records and replays QPainter commands -- your drawing --
Evvy answered 14/2, 2018 at 8:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.