Is there any example Qt code which displays the image from an unsigned char display buffer? Each byte on the buffer corresponds to the Gray scale pixel color. The content of the display buffer changes at run time in specified intervals. I need to change the display buffer content as fast as I can, so that the image seems to be moving. My question is how to draw pixels from the buffer very fast? I don’t need to save the image, just want to display it. Please help
Asked
Active
Viewed 2,988 times
1 Answers
2
QImage
provides a constructor for initialization using an unsigned char
buffer. In order to display it you could use a QGraphicsView
with a QGraphicsScene
. Every time the data of the buffer changes you could call a slot similar to the following one:
void updateImage()
{
// I assume an 1024x768 image
QImage img(buffer, 1024, 768, QImage::Format_Indexed8);
scene->clear();
scene->addPixmap(QPixmap::fromImage(img));
graphicsView->update();
}
You could also use the QPixmap
's loadFromData
in order to load directly the pixmap from the unsigned char array and avoid the QImage
step.

pnezis
- 12,023
- 2
- 38
- 38
-
I use Qimage instead of QPixmap. But the image shown is always black even though the data in buffer changes – indira Mar 12 '12 at 09:22
-
unsigned char buffer[50*200] = {150}; QImage img(buffer, 50, 200, QImage::Format_Indexed8); m_scene->clear(); m_scene->addPixmap(QPixmap::fromImage(img)); m_view->update(); – indira Mar 12 '12 at 09:44
-
`unsigned char buffer[50*200] = {150}` : This call will create a buffer with the following contents `[150,0,0,0,0,0,0,....,0]` so a black image will be displayed and only the top left pixel will have a grayscale value of 150. – pnezis Mar 12 '12 at 09:49