Can't QImage save BMPs with 16 bits color depth?

  • Hello,

    I'm trying to use QImage to save 16-bit bmps (Format_RGB16, Format_RGB555, Format_RGB444), but it always saves it as 32 bits.

    Here's a test code snippet:
    @#include <QtCore>
    #include <QImage>
    #include <QTextStream>
    #include <QFile>

    int main(int argc, char *argv[])
    QTextStream out(stdout);
    if (argc < 2)
    out << "Usage: " << argv[0] << " <filename> [<filename> ...]" << endl;

    for (int i = 1; i < argc; i++)
      QString fname = argv[i];
      if (!QFile::exists(fname))
        out << "File not found: " << fname << endl;
        QImage img(fname);
        out << "Converting: " << fname << endl;
        out << "before: " << img.depth() << endl;
        QImage img2 = img.convertToFormat(QImage::Format_RGB16);
        out << "after: " << img2.depth() << endl;"new_" + fname);
        img2.load("new_" + fname);
        out << "reloaded: " << img2.depth() << endl;
    out << "Finished." << endl;


    That results in:
    $ ./makeRgb16 scrMain.bmp
    Converting: scrMain.bmp
    before: 32
    after: 16
    reloaded: 32

    In other words, while loaded in the QImage object it says it has a 16bit color depth, but after saving and loading the same image, it comes back as 32 (and the resulting "16bit" file size is identical to the original file).

    Also strange is that identify (from imagemagick) says the bmp files are 24 bits (RGB888), not 32.

    Is this "as designed", or a bug? I'm using Qt 4.7.0 (kubuntu 10.10).


    Joao S Veiga

  • I could reproduce this problem, only converting to Format_Indexed8 seemed to work, none of the RGB or ARGB formats work. I think you should log a bug for this

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.