Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.5.1
-
None
-
KUbuntu 14.04 32-bit
Description
Consider the following example:
#include <QtCore> #include <QtGui> int main(int argc, char **argv) { #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) QGuiApplication app(argc, argv); #else QApplication app(argc, argv); #endif QFile file("data.bin"); if(!file.open(QFile::ReadOnly)) qFatal("Cannot open file: %s", qPrintable(file.errorString())); QByteArray ba = file.readAll(); QImage::Format format = QImage::Format_Indexed8; QVector<QRgb> table; for(int i = 0;i < 255;i++) table.append(qRgb(i, i, i)); QImage image(reinterpret_cast<const uchar *>(ba.constData()), 850, 1400, 850, format); if(image.isNull()) qFatal("Image is null"); image.setColorTable(table); // // Workaround: // // if(!image.convertToFormat(QImage::Format_RGB32).save("qt.jpg")) // qFatal("Cannot save JPEG"); // if(!image.save("qt.jpg")) qFatal("Cannot save JPEG"); if(!image.save("qt.png")) qFatal("Cannot save PNG"); qDebug("Success"); return 0; }
The sample code tries to save binary data as PNG and JPEG. PNG has been saved correctly. JPEG looks like a negative (see attach). To workaround the bug one needs to explicitly convert the image to the RGB format, then JPEG works fine too. Binary data is attached.