Loading a QPixmap from raw data
Hi,
For a computer vision class I'm writing a program to capture images from a webcam using opencv and then displaying it in a Qt GUI. The capture all works, and I copy the 3 channel OpenCV image to the 4 byte aligned format necessary for Qt in my capture thread (here's a fast implementation of that: http://www.qtcentre.org/forum/p-qima...ostcount7.html ). Then in my widget's paint event I have this:
Code:
if(imageData) {
painter.
drawImage(QPoint(0,
0), tImg
);
}
else {
painter.setBrush(Qt::black);
painter.drawRect(rect());
}
}
This works fine and displays correctly, but I really don't like the fact that I'm creating a QImage only to then have it converted to a QPixmap for painting which wastes time (about 5-8% CPU time of a Athlon 64 3200 running at 1GHz)
QPixmap has a loadFromData function but it seems to expect an image encoded in PNG/GIF/JPG and won't take my raw 0xffRRGGBB data.
Is there any way to load a QPixmap from raw data like that or paint that data on screen in a more direct manner (OpenGL is not an option)?
Re: Loading a QPixmap from raw data
You will always have to convert between image and pixmap, because image data is stored locally and pixmap data is stored on the X server.
By the way... as far as I know the conversion on Windows is almost transparent so you shouldn't have an overhead here.