Results 1 to 2 of 2

Thread: Display an image from a unsigned char array

  1. #1
    Join Date
    May 2009
    Location
    Brazil
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Display an image from a unsigned char array

    Hi there!

    I am trying to display an image from an unsigne char array. Tried many things like the QPixmap.loadfromdata method and the label->pixmap property. Nothing worked so far.
    Does anyone have an example or something that could "inspire" me to get that?
    Thanks in advance,

    Percy.

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display an image from a unsigned char array

    I had same needs and never succeed with QImage::loadFromData since you need to write the header I presume.


    Just create a QImage with the right pixel size, with the format QImage::Format_Indexed8
    Then get acces buffer data in read/write with scanline, and use memset to copy from your buffer into the image buffer in a loop.

    You can set color values in your color table for each different pixel with QImage::setColor . Each pixel value of your source buffer is the index and you need to convert your colors into QRgb. Empty entries will be not used.

    There is another way to copy the whole buffer in one instruction with QImage::bits but since buffer inside the image is 32bits aligned, you will get an offset and unexpected result.

Similar Threads

  1. Char array[6] to QString and display it
    By arunvv in forum Newbie
    Replies: 11
    Last Post: 12th March 2014, 21:48
  2. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 16:36
  3. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 22:55
  4. How to Read and display BMP image using QT
    By agsrinivasan in forum Qt Programming
    Replies: 3
    Last Post: 29th January 2007, 08:14
  5. unable to save QCStrings properly in a buffer
    By nass in forum Qt Programming
    Replies: 13
    Last Post: 15th November 2006, 21:49

Tags for this Thread

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.