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. QImage Class, loading an image results in different behaviour between debug and release

QImage Class, loading an image results in different behaviour between debug and release

Scheduled Pinned Locked Moved Solved General and Desktop
qimageformatforcebmpgrayscale
5 Posts 2 Posters 2.1k Views
  • 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.
  • R Offline
    R Offline
    R4P70R
    wrote on 25 Oct 2017, 13:06 last edited by R4P70R
    #1

    I have found the root of my image display problem after some investigations but I still don't understand if this is actually a bug.
    My program is working fine in release but not really in debug sessions.

    Here is the part. I load a 2048x2048 grayscale 8bits bmp image this way:

    QImage image(":/v3_res.bmp");

    Then if I verify the image format:

    qDebug() << "image format is " << image.format();
    qDebug() << "image size is " << image.byteCount();

    Output from release:
    image format is 3
    image size is 4194304

    Output from debug:
    image format is 4
    image size is 16777216

    While this is actually the same image, the pixel format is not the same.

    Tried this:
    QImage image(2048,2048,QImage::Format_Indexed8);
    image.load(":/v3_res.bmp", "BMP");
    But it doesn't change format during debug.

    Also tried this:
    image = image.convertToFormat(QImage::Format_Indexed8);
    which show an image but looks kinda strange because you see it was not read in the correct format first.

    Image metadata looks correct (Windows report 8 Bits depth) and file size is 4'195'382 bytes

    So I have 2 questions now:
    Is this a bug?
    Is there a way to force the format during the creation of the QImage with a filename?

    Thank you for your answers

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 25 Oct 2017, 13:52 last edited by
      #2
      • could you upload the file somewhere so we can test it?
      • what version of Qt, compiler and OS are you using?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • R Offline
        R Offline
        R4P70R
        wrote on 25 Oct 2017, 14:16 last edited by R4P70R
        #3

        I upload it here
        https://drive.google.com/file/d/0B8NvEIhEx_TfQTBVc3JYb3NjMHM/view?usp=sharing
        File was found in png on internet, converted to 256-grayscale and saved to bitmap using XnView

        I'm using
        Qt 5.8.0 MinGW 32bit (mingw53_32)
        MinGW 5.3.0 32bit
        Windows 10 Pro 64 (v1703)

        1 Reply Last reply
        0
        • R Offline
          R Offline
          R4P70R
          wrote on 26 Oct 2017, 08:45 last edited by
          #4

          Just to update the issue, I tried the minimal code to load this image and it works now correctly everytime in debug too.. format 3 (QImage::Format_Indexed8) is reported for both.

          The issue is probably coming from somewhere else but it will be very difficult to track it down now...
          The code is exactly:
          "
          QImage image(":/v3_res.bmp");
          qDebug() << "image format is " << image.format();
          qDebug() << "image size is " << image.byteCount();
          "
          And I don't understand how it may be related to anything else in my software.

          Still looking for a way to force this in a manual way for the moment.

          1 Reply Last reply
          0
          • R Offline
            R Offline
            R4P70R
            wrote on 26 Oct 2017, 11:03 last edited by
            #5

            Ok, I think a clean and rebuild of the whole project did the trick.

            I always forget when I don't use it for sometimes. When something is doing weird with Qt you have to clean, qmake or rebuild to get everything in order.

            I will tag this issue as solved !

            1 Reply Last reply
            0

            3/5

            25 Oct 2017, 14:16

            • Login

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