Qt. The fastest way to draw 1024x1024 pixels on the screen

I am developing a program that should calculate the color of each point in the image 1024x1024 using a special algorithm. The color of the dot represents some value. Therefore, each point is independent of other points and must be compiled separately. I do not need to refresh the image too often. In fact, I need to display it only once.

What is the fastest way to draw individual pixels in Qt?

Is it possible to get some kind of โ€œon-screen memoryโ€ and write the whole image as an array of 4-byte sets representing each pixel as 4 bytes in this memory?

+8
qt image pixel drawing
source share
3 answers

The QImage class is optimized for pixel manipulation. You can create an instance with the required size, and then either set the individual pixels of setPixel , or access the raw data and manage it in place using bits() . Just make sure you use the correct format (e.g. RGBA values โ€‹โ€‹or color indices for 8-bit images)

+7
source share

The quickest solution would be to create a QImage , manage it (set pixels), and then get Qt to draw it.

The QImage class is designed for quick I / O, from the manual:

The QImage class provides a device-independent image representation that provides direct access to pixel data and can be used as a drawing device.

The QImage class supports several image formats described in the Format enumeration. These include monochrome, 8-bit, 32-bit and alpha-mixed images, which are available in all versions of Qt 4.x.

The detailed description section contains information on manipulating pixels.

To display it, the easiest way would be to convert it to pixmap using QPixmap::fromImage and then put it in the label using QLabel::setPixmap .

For more control, you can subclass QWidget , overload paintEvent and draw a QImage using QPainter using QPainter::drawImage .

+6
source share

You can try using the OpenGL widget and glDrawPixels .

+2
source share

All Articles