Question

I'm currently combining the Qt library with the Kinect API, and attempting to show the video from the sensor in a QImage (being shown by a QLabel).

In my Kinect handling library, the function that receives the data from the video sensor is emitting the data as a BYTE* (pointing to something with RGB32 values).

In another little corner of my program, I have a slot receiving that BYTE* and attempting to update the QImage with the RGB32 data as follows:

videoCanvas->loadFromData(reinterpret_cast<const uchar*>(pBuffer), QImage::Format_RGB32);

Where pBuffer is passed into the slot by the signal, and is the aforementioned BYTE*.

This is not working for me, and I'm still stuck with a gray box where the image should be. I imagine that the issue is in the casting, because I have researched the data type and apparently QImage::Format_RGB32 is correct.

How should I proceed with this? :)

Was it helpful?

Solution

loadFromData expects the buffer you are passing to have all the necessary information about the image...including its width and height. So the format should be things like JPEG or PNG, not a QImage::Format constant.

In fact, I'm surprised that line compiled as written...because loadFromData expects a char* for it's specification of the "format", and you're passing an integer:

http://developer.qt.nokia.com/doc/qt-4.8/qimage.html#Format-enum

If what you have is a raw byte array of data, and know the width and height from some other source, you probably want to use the appropriate QImage constructor for that:

http://developer.qt.nokia.com/doc/qt-4.8/qimage.html#QImage-5

That's where you use the QImage::Format values...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top