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. QImageReader could not find the size of images
Forum Updated to NodeBB v4.3 + New Features

QImageReader could not find the size of images

Scheduled Pinned Locked Moved Unsolved General and Desktop
pictureqt6windowsimageformats
8 Posts 3 Posters 154 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.
  • Grit ClefG Offline
    Grit ClefG Offline
    Grit Clef
    wrote last edited by Grit Clef
    #1

    Hi,
    Using Qt 6.9 on Windows 11 23H2, I found that QImageReader couldn't work properly on some formats, especially in getting the pictures' size info. In particular, I tested bmp, png, jpg formats, and found that QImageReader would only give me the right info of the jpg formatted pictures. For example, the following code:

    QImageReader imgReader;
    imgReader.setFileName("...");
    imgReader.setAutoTransform(true);
    
    if (imgReader.canRead()) {
        QMessageBox::warning(nullptr, "...", QString::number(imgReader.size().width()),
                                         QMessageBox::Close);
    }
    

    will tell me the correct width of a jpg image, while only -1 of pictures in other formats.
    Surprisingly, if I then read a pixmap from that QImageReader, use the getters from that QPixmap, and I would see all the correct info.

    QPixmap pixmap{ QPixmap::fromImageReader(&imgReader) };
    QMessageBox::warning(nullptr, "...", QString::number(pixmap.width()),
                                         QMessageBox::Close);
    

    The result above is always right.
    Also, I've tested the supportsOption function:

    imgReader.supportsOption(QImageIOHandler::Size);
    

    It's always true.
    Why is it? It's so strange that I think I may look for help. Thanks.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote last edited by
      #2

      Hi,

      I have not checked the code of these readers but from a quick look at the QImagrReader::size documentation they might fall in the category of "needs to be fully read to get that information".

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Grit ClefG Offline
        Grit ClefG Offline
        Grit Clef
        wrote last edited by Grit Clef
        #3

        Qt's built-in image handlers all support this feature

        I was just confused by that sentence. Formats like BMP are built in, but their size cannot be determined until they are fully read... Doesn't the BITMAPINFOHEADER contain useful information about its width and height?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote last edited by
          #4

          The BMP handler should give that information unless something wrong happened when reading the file header.

          Can you provide a minimal compilable example with a sample images that would allow to check what happens ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote last edited by Christian Ehrlicher
            #5

            And create a bug report and notify me so I can take a look on it after holidays. I would expect that the size is always returned correctly, no matter if we have to read the whole file or not. I know it is working for png and assume it must work for others in QIconloader class so it is important to see if there is something wrong.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            0
            • Grit ClefG Offline
              Grit ClefG Offline
              Grit Clef
              wrote last edited by
              #6

              I think I have learnt sth. For handlers like BMP, we cannot do reading operations before calling size(). If I call size() immediately after canRead(), the result is correct; if I have called read() or sth like QPixmap::fromImageReader() before the call to size(), the result is invalid. However for the JPG handler, there's no such restriction.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote last edited by
                #7

                Please create a bug report

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                0
                • Grit ClefG Offline
                  Grit ClefG Offline
                  Grit Clef
                  wrote last edited by
                  #8

                  Create at https://bugreports.qt.io/browse/QTBUG-138530

                  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