Important: Please read the Qt Code of Conduct -

FromImage not Keeping Indexed Color Table

  • I am dealing with large 16-bit grayscale images. They are displayed at 8-bit where I have to be able to adjust contrast/brightness, add text labels, some basic forms like rectangles/lines/etc. To keep the memory footprint low I want to keep them as 8-bit rather than RGBA. However, when I do fromImage, my 8-bit data automatically seems to be converted to RGBA (judging by how much memory is being used up). How can I keep this as 8-bit data (or even 16-bit while allowing contrast/brightness adjustment)? Here is my code:

    QImage image(data, width, height, lineWidth, QImage::Format_Indexed8);
    QVector<QRgb> grayscaleTable;
    for (int i = 0; i < 256; i++)	grayscaleTable.push_back(qRgb(i, i, i));
    pixmap = scene->addPixmap(pixmap);

  • Hi,
    QImages are for image processing: working with color tables, access to individual pixels etc. QPixmap on the other hand, is more for fast blitting to a screen. So, it uses the default color depth of your screen, which will probably be 32-bit.
    I would say: there is no way to use QPixmap with 16-bit color depth when you have a 32-bit screen.

Log in to reply