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:
if(imageData) {
painter.
drawImage(QPoint(0,
0), tImg
);
}
else {
painter.setBrush(Qt::black);
painter.drawRect(rect());
}
}
void RenderWidget::paintEvent(QPaintEvent*) {
QPainter painter(this);
if(imageData) {
QImage tImg(imageData, 640, 480, QImage::Format_RGB32);
painter.drawImage(QPoint(0,0), tImg);
}
else {
painter.setBrush(Qt::black);
painter.drawRect(rect());
}
}
To copy to clipboard, switch view to plain text mode
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)?
Bookmarks