PDA

View Full Version : QBytearray to QGraphicview



rno
3rd June 2016, 18:28
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)


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.

QVector<QRgb> my_table;
for(int i = 0; i < 256; i++) my_table.append(qRgb(i,i,i));
image.setColorTable(my_table); //this does not work i.e. has no effect on the image. the displayed image is on a green scale.

m_scene->addPixmap(QPixmap::fromImage(image);
.

Cheers,
Rno

ChrisW67
3rd June 2016, 22:11
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