Fastest way to draw 1024x1024 dots on screen
The QImage
class is optimized for pixel manipulation. You can instantiate one with the requred size and then either set the pixels individually setPixel
, or access the raw data and manipulate them in place via bits()
. Just be sure to use the correct format (e.g. RGBA values or color indices for 8-bit images)
The fastest solution may be to create a QImage
, manipulate it (set the pixels) and then get Qt to draw it.
The QImage class is for fast IO, from the manual:
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.
The QImage class supports several image formats described by the Format enum. These include monochrome, 8-bit, 32-bit and alpha-blended images which are available in all versions of Qt 4.x.
There is information on pixel manipulation in the Detailed Description section.
To display it the simplest way would be to convert it to a pixmap with QPixmap::fromImage
and then put it in a label with QLabel::setPixmap
.
For more control, you could sub-class QWidget
, overload the paintEvent
, and draw the QImage with a QPainter
with QPainter::drawImage
.