Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't QImage save BMPs with 16 bits color depth?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 4.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jsveiga
    wrote on last edited by
    #1

    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;
      else
      {
        QImage img(fname);
        out << "Converting: " << fname << endl;
        out << "before: " << img.depth() << endl;
        QImage img2 = img.convertToFormat(QImage::Format_RGB16);
        out << "after: " << img2.depth() << endl;
        img2.save("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
    Finished.

    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).

    Thanks!

    Joao S Veiga

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved