Results 1 to 5 of 5

Thread: QImage and 8 bit unsigner char **

  1. #1
    Join Date
    May 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QImage and 8 bit unsigner char **

    Hi all,

    I need to display a tiff image on a QWidget, the image is 8 bit-depth, and I need to represent it using 2 dimensional unsigned char so that it can be processed later. I've successfully read the tiff image into the char, but I can't draw it on the QWidget. What I've tried is:

    Qt Code:
    1. unsigned char pic[512][512] = TiffIO::tiffReadPic("test.tif", pic, &width, &height);
    2. QImage img(width, height,QImage::Format_Indexed8);
    3.  
    4. for(int i = 0; i < 255; i++)
    5. {
    6. myColor = qRgb(i, i, i);
    7. img.setColor(i, myColor);
    8. }
    9.  
    10. for(int i = 0; i<width; i++)
    11. for(int j = 0; j<height; ++j)
    12. img.setPixel(i, j, pic[i][j]);
    To copy to clipboard, switch view to plain text mode 

    But it doesn't give anything, the QWidget remains blank and no error message at all

    Any suggestion?

    Thanks...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage and 8 bit unsigner char **

    How do you draw that image on QWidget? How does this image look like if you save it to a file using QImage::save()?

  3. #3
    Join Date
    May 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage and 8 bit unsigner char **

    Thanks for your very fast reply,

    I'm sorry, I got error message with that code from QImage that the pixel I try to set is always out of range (QImage::setPixel: index=15 out of range). Then I tried to print img.numColors(), and I found that it always returns 0, even though I've set the format to 8 bit indexed (QImage::Format_Indexed8). However if I set the numColors manually via img.setNumColors(256), that piece of code works, the QWidget and also img.save() produce correct images.

    I still don't understand why 8 bit indexed can have 0 numColors() ? From the doc, I read QImage will not return 0 from image that uses color table. Or maybe I miss something?

    Thanks btw

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImage and 8 bit unsigner char **

    If you choose the format of QImage, you only set a way of storing pixel data in the object. You have to set the number of colours manually using setNumColors() then probably to set the proper size of the CLT.

  5. #5
    Join Date
    May 2006
    Posts
    5
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage and 8 bit unsigner char **

    Quote Originally Posted by wysota
    If you choose the format of QImage, you only set a way of storing pixel data in the object. You have to set the number of colours manually using setNumColors() then probably to set the proper size of the CLT.
    Oh, I didn't know about that before, thanks for your explanation

Similar Threads

  1. [Qt4] How to load Url image into QImage?
    By Gonzalez in forum Qt Programming
    Replies: 6
    Last Post: 13th October 2014, 10:10

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.