PDA

View Full Version : Problem in displaying RGB32 data



bmn
16th June 2008, 11:29
void Custom_window::display()
{
if(i<5){
printf("\n Calling Capture function\n");
uchar* data = (uchar*)function(); //data is in bgr32 bit format
QPixmap *p;
// Frame display
image = new QImage(data,640,480,QImage::Format_RGB32);
label->setPixmap(p->fromImage(*image));
textmessage->append("The path of the file is");
i++;
}
else
i=0;
}

Unable to display the image. Need help

spud
16th June 2008, 13:47
Your code is basically correct, although you could change it to:

uchar* data = (uchar*)function(); //data is in bgr32 bit format
// Frame display
QImage image(data, 640, 480, QImage::Format_RGB32);
label->setPixmap(QPixmap::fromImage(image));

Of course you have to be certain that function() returns a pointer to 640*480*4 bytes of data which remain valid until after setPixmap has been called.

So, what do you see? is anything displayed?

spud
16th June 2008, 14:30
Sorry, but I just realized that the above code needs data to remain valid for a longer time.
A safer way would be to copy the image data.

QImage image(640, 480, QImage::Format_RGB32);
memcpy(image.bits(), data, 640*480*4);
label->setPixmap(QPixmap::fromImage(image));