[Qt-interest] QPixmap / QImage performance question

Samuel Rødal sroedal at trolltech.com
Mon Jul 27 09:58:37 CEST 2009


Lucas Jacobs wrote:
> Thanks for your response. I knew of easy ways to provide read/write
> access to pixels within a QImage, like bits(), scanLine() and
> QImage(uchar *data, ...), but as I currently understand Qt's image
> support:
> 
> - QImages cannot be displayed to the screen. They must be converted to
> QPixmap objects first.

They can be displayed directly using QPainter::drawImage(). If the image 
is only going to be drawn once between modifications, this is probably 
the fastest approach. If the image is modified and then drawn a lot of 
times QPixmap::fromImage() and QPainter::drawPixmap() might be faster.

> - Individual pixels of a QPixmap cannot be read by users without
> obtaining system-specific bitmap handles like HBITMAP.

Correct, to read individual pixels a pixmap should be converted back to 
a QImage.

> - Looking through QPixmap's implementation, QPixmap::fromImage()
> copies all pixel data from the QImage into another allocated block of
> memory at least once, also checking for alpha pixels among other
> things.

This depends on the graphics system being used. With the raster graphics 
system (default on Windows and embedded Linux) no copying is done, at 
least if the image is already in RGB32 or ARGB32_Premultiplied format.

--
Samuel



More information about the Qt-interest-old mailing list