Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between QImage and QPixmap?

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?

like image 724
Mr.Tu Avatar asked Apr 25 '12 00:04

Mr.Tu


People also ask

How do you convert QImage to QPixmap?

A QPixmap object can be converted into a QImage using the toImage() function. Likewise, a QImage can be converted into a QPixmap using the fromImage(). If this is too expensive an operation, you can use QBitmap::fromImage() instead.


1 Answers

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.
like image 58
karlphillip Avatar answered Sep 27 '22 19:09

karlphillip