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"
-
Hi,
What version of Qt ?
On what OS ?
Which compiler ?
Is that tiff file available somewhere to test ? -
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 ?
-
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.
-
Hi
mingw 32 bit gave
"Error loading compressed image"
Sadly its not possible to test with mingw 64 -
@j_omega
Well at least to 32 bit.
If possible i will try vs 20015 32 bitIts 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