我有以下代码.
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不在路上. …