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 won't load a jpg that it saved
QtWS25 Last Chance

QImage won't load a jpg that it saved

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 2.3k 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.
  • J Offline
    J Offline
    j_omega
    wrote on last edited by j_omega
    #1

    I have the following code which creates a compressed version of an image to work with

    
    qDebug() << "creating copmressed image";
    
    if(!image.load("../resources/image.tif"))
    {
    	qDebug() << "Error loading image...";
    }
    if (!image.save("../resources/image_compressed.jpg", Q_NULLPTR, 10))
    {
    	qDebug() << "Error saving image...";
    }
    if (!image.load("../resources/image_compressed.jpg"))
    {
    	qDebug() << "Error loading compressed image";
    }
    
    

    The code opens the tiff and saves it successfully but then fails to load the jpg that it just saved. What am I missing here? I can view the compressed JPG in window photo viewer.

    The output of qDebug() << QImageWriter::supportedImageFormats() is

    ("bmp", "cur", "icns", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "tif", "tiff", "wbmp", "webp", "xbm", "xpm")
    

    Also

    QImageReader test("../resources/image_compressed.jpg");
    qDebug() << test.errorString();
    

    gives "Unknown error"

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

      Hi,

      What version of Qt ?
      On what OS ?
      Which compiler ?
      Is that tiff file available somewhere to test ?

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

      J 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        What version of Qt ?
        On what OS ?
        Which compiler ?
        Is that tiff file available somewhere to test ?

        J Offline
        J Offline
        j_omega
        wrote on last edited by
        #3

        @SGaist
        5.9.3
        Windows 7
        mingw53_32

        Here is the file
        http://aeronav.faa.gov/content/aeronav/sectional_files/Chicago_95.zip

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

          I tested that on macOS with 5.10 and the image was creating correctly although there was some warning about unknown fields when reading the tif file.

          I have loaded it in a QLabel and it showed. In your case, the "unknown error" is likely the equivalent of "no error".

          Did you try to open the resulting jpeg with an image viewer ?

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

          J 1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi
            I tried your code with 5.10, visual stud 2015 64 bit, win 10.
            and it just loaded. ( it took a few secs.)

            void DelegateTableViewDialog::on_pushButton_2_released() {
              QImage image;
              qDebug() << "creating copmressed image";
            
              if(!image.load("e:/image.tif")) {
                qDebug() << "Error loading image...";
              }
              if (!image.save("e:/image_compressed.jpg", Q_NULLPTR, 10)) {
                qDebug() << "Error saving image...";
              }
              if (!image.load("e:/image_compressed.jpg")) {
                qDebug() << "Error loading compressed image";
              } else
                  ui->label_2->setPixmap( QPixmap::fromImage(image) );
            }
            
            

            The jpg was 13.5 MB.

            1 Reply Last reply
            1
            • SGaistS SGaist

              I tested that on macOS with 5.10 and the image was creating correctly although there was some warning about unknown fields when reading the tif file.

              I have loaded it in a QLabel and it showed. In your case, the "unknown error" is likely the equivalent of "no error".

              Did you try to open the resulting jpeg with an image viewer ?

              J Offline
              J Offline
              j_omega
              wrote on last edited by j_omega
              #6

              @SGaist Yes, I can view it in an image viewer.

              Can you try using MinGW? So far I have had nothing but trouble with MinGW...

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                Hi
                mingw 32 bit gave
                "Error loading compressed image"
                Sadly its not possible to test with mingw 64

                J 1 Reply Last reply
                1
                • mrjjM mrjj

                  Hi
                  mingw 32 bit gave
                  "Error loading compressed image"
                  Sadly its not possible to test with mingw 64

                  J Offline
                  J Offline
                  j_omega
                  wrote on last edited by
                  #8

                  @mrjj So would you agree that this is a Qt bug specific to MinGW 32?

                  mrjjM 1 Reply Last reply
                  0
                  • J j_omega

                    @mrjj So would you agree that this is a Qt bug specific to MinGW 32?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    @j_omega
                    Well at least to 32 bit.
                    If possible i will try vs 20015 32 bit

                    Its hard to imagine if mingw would produce wrong code (its pretty mature). its more likely
                    something with QImage and 32 bit and massive tiff file.

                    Update:
                    with vs 2015 32-bit it dies with
                    alt text

                    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