Saving QPixmap with JPEG error (Qt 4.5)

I have the following code.

QString fileName = QFileDialog::getSaveFileName(
   this, 
   tr("Output Image file"),
   (""),
   tr("PNG (*.png);;JPEG (*.JPEG);;Windows Bitmap (*.bmp);;All Files (*.*)")
);

if(fileName != "")
{
   QwtPlot* pPlot = ...
   QSize size = pPlot->size();
   QRect printingRect(QPoint(0, 0), size);

   QPixmap pixmapPrinter(size);
   pixmapPrinter.fill(Qt::white);

   {
      QPainter painter(&pixmapPrinter); 
      pPlot->print(&painter, printingRect);     
   } 

   bool isOk = pixmapPrinter.save(fileName);

   if(!isOk)
   {                
      QString msgText = tr("Failed to write into ") + fileName;

      QMessageBox::critical(this, tr("Error Writing"), msgText);
   }
}

So, the path is as follows: - a dialog with a file pops up - users select a format and file - the system draws a graph on QPixmap - saves QPixmap to a file.

It works for PNG and BMP without problems, but for JPEG, JPG, JPG, etc. he does not work.

I had full Qt documentation, but I could not find any details. It should just work. Any ideas?

I am using the commercial version of Qt, 4.5.1 for Windows.
I am using dlls, Qt is not on the way.

I just realized that I am linking statically with the classic third-party jpeg.lib (independent JPEG Group JPEG software), which is used by another library.

Is it possible that this is causing a conflict or something else?

.

+3
3

, ...

imageformats .

imageformats .

(, jpeg-)

+5

, QTPLUGIN += qjpeg .pro , jpeg .

+4

, , , - , .

, :

QString fileFormats = "(";
/* Get all inputformats */
for (int i = 0; i < QImageReader::supportedImageFormats().count(); i++) {
    fileFormats += "*."; /* Insert wildcard */
    fileFormats
            += QString(QImageReader::supportedImageFormats().at(i)).toLower(); /* Insert the format */
    fileFormats += " "; /* Insert a space */
}
fileFormats += ")";

QString fileName = QFileDialog::getOpenFileName(this, tr("Open Image"),
        currentPath, tr("Images ") + fileFormats);

, QA-. Debug .

+4
source

Source: https://habr.com/ru/post/1712850/


All Articles