将QPixmap保存为JPEG失败(Qt 4.5) [英] Saving QPixmap to JPEG failing (Qt 4.5)

查看:1203
本文介绍了将QPixmap保存为JPEG失败(Qt 4.5)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码。

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);
   }
}

所以,路径是这样:弹出 - 用户选择格式和文件 - 系统绘制图到QPixmap - 将QPixmap保存到文件中。

So, the path is like this: - File dialog pops up - users selects format and file - the system draws plot onto QPixmap - Saves QPixmap into the file.

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

It works for PNG and BMP without a problem, but for JPEG, jpg, JPG, etc it fails.

我是Qt的所有文档,但找不到任何细节。它应该工作。
任何想法?

I was all over Qt documentation but could not find any details. It should just work. Any ideas?

我使用的是Qt商业版,4.5.1 for Windows。

我使用的是dll,Qt不在路径上。

I am using Qt commercial edition, 4.5.1 for Windows.
I am using dlls, Qt is not on the path.

我刚刚意识到,我静态链接到经典的第三方jpeg.lib(独立JPEG组的JPEG软件),其他图书馆。

I just realised that I am linking statically to a classical 3rd party jpeg.lib (The Independent JPEG Group's JPEG software), which is used by other library.

这是否有可能发生冲突或事情?

Is it possible that a conflict or something arises because of this?

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

Or it is simply that plugin is not loaded properly.

推荐答案

可能它找不到插件...

probably it cant find the plugin...

你可以添加库路径到项目,或者你可以简单地把imageformats文件夹附近你的二进制。

you can add library path to project or you can simply put imageformats folder near your binary.

imageformats文件夹在插件..

imageformats folder is in plugins..

(可能你不能显示jpeg图片)

(probably you cant display jpeg images too)

这篇关于将QPixmap保存为JPEG失败(Qt 4.5)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆