Results 1 to 20 of 21

Thread: Using a 2d data array to create an image

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Using a 2d data array to create an image

    8bit images use a colour look-up table thus the value you put as pixel data is the index in the colour table which is probably empty thus you get all black. QPixmap will always be 32b. Reading documentation really doesn't hurt - try it.

  2. #2
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Using a 2d data array to create an image

    Thanks wysota, yes RTFM, i've said that in the past

    I assume that the conversion from 8bpp to 32bpp doesnt scale the pixel values and that is why my label is black?

    Do I have to create a colour table, how do I associate the colour table with my pixmap? I am confused.

    Best Regards

  3. #3
    Join Date
    Oct 2008
    Posts
    74
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: Using a 2d data array to create an image

    Still having problems with this, I have realised I need to create a colortable which I have populated with 'yellow' for all entries, so expecting a yellow image. The image is still black.
    My code is below

    QImage BPlaneI(ch_ptr,rows,cols,QImage::Format_Indexed8);//8 bit image
    BPlaneI.setNumColors(256);
    loadImageData(ch_ptr,rows,cols,&BPlaneI);//load image buffer from ch_ptr

    for (int i=0; i<255; i++)
    {
    BPlaneI.setColor(i,Qt::darkYellow);
    }

    QPixmap qp(rows,cols);
    qp.fromImage(BPlaneI,Qt::AutoColor);

    QLabel l;
    l.setPixmap(qp);
    l.show();

    Really stuck with this one, any ideas would be greatly appreciated

    Thanks

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

    Default Re: Using a 2d data array to create an image

    Quote Originally Posted by dbrmik View Post
    I assume that the conversion from 8bpp to 32bpp doesnt scale the pixel values and that is why my label is black?
    I'm not sure what you mean by that but I think the answer is "no".

    Do I have to create a colour table, how do I associate the colour table with my pixmap? I am confused.
    Try something obvious:
    Qt Code:
    1. QImage image(100,100, QImage::Format_Indexed8);
    2. image.setNumColors(2);
    3. image.setColor(0, qRgb(0,0,0));
    4. image.setColor(1, qRgb(255,255,0));
    5. image.fill(0);
    6. for(int i=0;i<100;i++)
    7. image.setPixel(i, i, 1);
    8. QLabel *label = new QLabel;
    9. label->setPixmap(QPixmap::fromImage(image));
    10. label->show();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 2
    Last Post: 29th September 2008, 00:08
  2. Creating a Pixmap out of an array of data
    By toratora in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2007, 19:00
  3. Help needed handling image data
    By toratora in forum General Programming
    Replies: 2
    Last Post: 11th May 2007, 09:24
  4. how to create resource fork & data fork
    By jyoti in forum General Discussion
    Replies: 4
    Last Post: 28th November 2006, 17:20
  5. How to create QPixmap from unsigned character array?
    By rashidbutt in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 18:25

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
  •  
Qt is a trademark of The Qt Company.