Display grayscale image using Qt

后端 未结 2 1746
天涯浪人
天涯浪人 2020-12-21 03:59

I have been trying to display a gray-scale image using Qt. The image data is loaded from a .txt file that contains 256x256 float data. There is no header involved for the im

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-21 04:19

    How are you loading the QImage with the grey image data ?

    QT doesn't have a greyscale image type, only a bilevel type. You can either create an RGB image with R=G=B=grey. Or more preferably use QImage::Format_Indexed8 and create a colour table where each entry has the same value as the index. i.e.

    QImage *qi = new QImage(data_ptr, width, height, QImage::Format_Indexed8);
    QVector my_table;
    for(int i = 0; i < 256; i++) my_table.push_back(qRgb(i,i,i));
    qi->setColorTable(my_table);
    

提交回复
热议问题