Results 1 to 2 of 2

Thread: Displaying an image from a char array

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Displaying an image from a char array

    Hello!

    I have the task of programming a gui that displays a video stream. Images arrive in a raw pixelwise format as an RGB char array. So each three consecutive bytes describe the R,G, and B component of one pixel (not 32 bit aligned!). Now I'm looking for the best way to solve this with Qt.

    Well, I could just draw the raw data as colored pixels (drawRect) in the paintEvent of a widget. This is probably going to be painfully slow.
    If I do this off screen on a QPicture and then draw the QPicture on the widget, is it going to be faster?

    Then there is QImage. I don't see a way how I could pour the raw data into the QImage with the fromData() or loadFromData() methods. It seems I will have to "set" the QImage pixel by pixel, and then convert it to QPixmap for drawing. This doesn't sound exactly fast either. Does any one have an idea / experience how I could accelerate this process? A high framerate and smooth display are quite crucial for this application.

    Would it be better if I rewrite the raw 24 bit buffer to a 32 bit aligned buffer and then go the from-buffer-constructed or fromData() way with a QImage? But then there is still the conversion to QPixmap, and it sounds like my raw pixelwise buffer is actually already in the ideal format to be displayed on the screen. Any ideas?

    Cruz

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Displaying an image from a char array

    First you could check if any of the QImage formats applies to your data, e.g. Format_RGB888.

    If not you could consider providing a QImageIOHandler for your format.

    High performance UI is often done via OpenGL, so you could have a look at that as well.

    Cheers,
    _

Similar Threads

  1. char array and char * array[]
    By vanduongbk in forum Newbie
    Replies: 6
    Last Post: 17th October 2013, 10:18
  2. char array to qstring
    By vani.pv in forum Newbie
    Replies: 4
    Last Post: 16th August 2012, 11:04
  3. Char array to QString
    By gab74 in forum Newbie
    Replies: 11
    Last Post: 13th December 2011, 15:54
  4. Display an image from a unsigned char array
    By Percy in forum Qt Programming
    Replies: 1
    Last Post: 1st December 2009, 20:16
  5. Char Array to QString
    By 3nc31 in forum Qt Programming
    Replies: 2
    Last Post: 25th November 2007, 22:18

Bookmarks

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.