将QPixmap保存为JPEG失败(Qt 4.5)

Den*_*s C 3 c++ qt qt4 qpixmap

我有以下代码.

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);
   }
}
Run Code Online (Sandbox Code Playgroud)

因此,路径是这样的: - 弹出文件对话框 - 用户选择格式和文件 - 系统将绘图绘制到QPixmap上 - 将QPixmap保存到文件中.

它适用于PNG和BMP没有问题,但对于JPEG,jpg,JPG等,它失败了.

我到处都是Qt文档,但找不到任何细节.它应该工作.有任何想法吗?

我正在使用Qt商业版,4.5.1 for Windows.
我正在使用dll,Qt不在路上.

我刚刚意识到我正在静态链接到经典的第三方jpeg.lib(独立JPEG组的JPEG软件),这是其他库使用的.

因此可能会发生冲突或其他事情吗?

或者只是插件没有正确加载.

ufu*_*gun 5

可能它找不到插件......

您可以将库路径添加到项目中,也可以将imageformats文件夹放在二进制文件附近.

imageformats文件夹在插件中..

(可能你也不能显示jpeg图像)