Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-138530

QImageReader could not determine the size of certain image formats

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • 6.9.0, 6.9.1
    • Image formats
    • None
    • Windows

    Description

      QImageReader couldn't get the picture's size of certain format.
      Sample Code:
      [main.cpp]

      #include <QApplication>
      #include <QFileDialog>
      #include <QString>
      #include <QByteArray>
      #include <QStringList>
      #include <QImageReader>
      #include <QMessageBox>
      #include <QPixmap>
      
      using namespace Qt::Literals::StringLiterals;
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
          
          QStringList mimeTypeFilters;
          const QByteArrayList supportedMimeTypes{ QImageReader::supportedMimeTypes() };
          for (const QByteArray &mimeTypeName : supportedMimeTypes)
              mimeTypeFilters.append(mimeTypeName);
      
          mimeTypeFilters.sort();
      
          QFileDialog fdlg;
          QImageReader imgReader;
          
          fdlg.setWindowTitle(u"Open a picture..."_s);
          fdlg.setDirectory(u"."_s);
          fdlg.setMimeTypeFilters(mimeTypeFilters);
          fdlg.setFileMode(QFileDialog::ExistingFile);
          fdlg.exec();
          
          imgReader.setFileName(fdlg.selectedFiles()[0]);
          imgReader.setAutoTransform(true);
      
          if (imgReader.canRead()) {
              QPixmap pixmap{ QPixmap::fromImageReader(&imgReader) };    // If this is added, the result will be incorrect.
              QMessageBox::information(nullptr, u"..."_s, 
                                       u"Width: "_s + QString::number(imgReader.size().width()) + u", Height: "_s + QString::number(imgReader.size().height()),
                                       QMessageBox::Close);
          }
                                           
          return a.exec();
      }
      

      I have found PNG and BMP handlers have that problem. In detail, 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 other handlers like JPG, there's no such restriction.

      Attachments

        1. res.tar
          280 kB
          Grit Clef
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            vgt Eirik Aavitsland
            zxunge Grit Clef
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes