QImage won't load a jpg that it saved



  • 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"


  • Lifetime Qt Champion

    Hi,

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




  • Lifetime Qt Champion

    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 ?


  • Qt Champions 2017

    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.



  • @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...


  • Qt Champions 2017

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



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


  • Qt Champions 2017

    @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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.