Results 1 to 2 of 2

Thread: Loading a QPixmap from raw data

  1. #1
    Join Date
    Aug 2006
    Thanked 49 Times in 36 Posts
    Qt products

    Default Loading a QPixmap from raw data


    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: ). Then in my widget's paint event I have this:

    Qt Code:
    1. void RenderWidget::paintEvent(QPaintEvent*) {
    2. QPainter painter(this);
    3. if(imageData) {
    4. QImage tImg(imageData, 640, 480, QImage::Format_RGB32);
    5. painter.drawImage(QPoint(0,0), tImg);
    6. }
    7. else {
    8. painter.setBrush(Qt::black);
    9. painter.drawRect(rect());
    10. }
    11. }
    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)?

  2. #2
    Join Date
    Jan 2006
    Warsaw, Poland
    Thanked 5,014 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits

    Default 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.
    Last edited by wysota; 27th January 2008 at 10:21.

  3. The following user says thank you to wysota for this useful post:

    pherthyl (30th January 2008)

Similar Threads

  1. Replies: 4
    Last Post: 19th October 2007, 19:47
  2. Loading jpeg (QPixmap with Qt Jambi)
    By Mr_Blonde in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2006, 18:06
  3. Loading a custom image into a QPixmap
    By KShots in forum Qt Programming
    Replies: 12
    Last Post: 5th August 2006, 00:16
  4. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53
  5. Replies: 16
    Last Post: 7th March 2006, 15:57


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.