Results 1 to 2 of 2

Thread: QBytearray to QGraphicview

  1. #1
    Join Date
    May 2011
    Posts
    17
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QBytearray to QGraphicview

    Hi,

    I have my data in a Qbytearray of 18 000 000 bytes. The data are unsigned shorts (i.e 2 bytes, 3000 x 3000 = 9 000 000).

    I would like to display my data as a grayscale image. I am not sure how to do it and I would like it to be fast.

    I have tried the code below but a couple of things doesn't work (see comments)
    Qt Code:
    1. QImage image = QImage((unsigned char *) BinaryArray.data(),3000,3000,QImage::Format_RGB16); //I am not sure at all about what is happening here but the resulting image is recognizable.
    2.  
    3. QVector<QRgb> my_table;
    4. for(int i = 0; i < 256; i++) my_table.append(qRgb(i,i,i));
    5. image.setColorTable(my_table); //this does not work i.e. has no effect on the image. the displayed image is on a green scale.
    6.  
    7. m_scene->addPixmap(QPixmap::fromImage(image);
    To copy to clipboard, switch view to plain text mode 
    .

    Cheers,
    Rno

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QBytearray to QGraphicview

    QImage does not have a format to load a 16-bpp greyscale image. RGB16 is a colour format with red, green, and blue components packed in 5, 6, and 5 bitts respectively. Treating greyscale data as RGB16 will give a recognisable image in false colours.

    QImage does have a format for an 8-bop greyscale (Grayscale8), but to use that you would have to pre-process your data. 18m samples at 16bpp compacted to 9m samples at 8bpp. A naive approach to this might simply be to divide each sample by 256.

    BTW Your post has nothing to do with QGraphicsView

Similar Threads

  1. Replies: 6
    Last Post: 14th May 2014, 12:14
  2. Insert image to QGraphicView
    By jmarshellk in forum Newbie
    Replies: 2
    Last Post: 22nd March 2013, 06:21
  3. QGraphicView Optimizing cpu
    By fkili in forum Newbie
    Replies: 4
    Last Post: 27th September 2012, 14:02
  4. How to use QGraphicView?
    By karthic in forum Newbie
    Replies: 12
    Last Post: 27th April 2012, 08:06
  5. my QGraphicView problem
    By irmakci in forum Qt Programming
    Replies: 3
    Last Post: 19th July 2008, 18:40

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.