Hi, how to save a plot (created by QWT) to a .jpg file?
Cheers
JIA
Hi, how to save a plot (created by QWT) to a .jpg file?
Cheers
JIA
Welcome to Vision Open
http://www.visionopen.com
Take a look at QPixmap and try somethihng like this:
Qt Code:
void Plot::saveAS() { pixmap.fill(Qt::transparent); QwtPlotPrintFilter filter; // options &= ~QwtPlotPrintFilter::PrintBackground; // options &= ~QwtPlotPrintFilter::PrintGrid; filter.setOptions(options); if(!pixmap.isNull()){ QString fileName = QFileDialog::getSaveFileName(this, tr("Save the file as..."), QDir::currentPath(), tr("JPEG (*.jpg);;Portable Network Graphics (*.png)")); if (!fileName.isEmpty()){ if(fileName.endsWith(".png")){ this->print(pixmap, filter); pixmap.save(fileName, "PNG"); } else if(fileName.endsWith(".jpg")){ this->print(pixmap, filter); pixmap.save(fileName, "JPG"); } else{ return; } } }To copy to clipboard, switch view to plain text mode
Thank you very much. It works.
However, as attached,
"shouldbe" is the plot that I should have obtained while
"obtained" is the wrong figure that I finally drew.
So, a further question:
How can I specify "including" the plot's X Axis and Y Axis (particularly, those descriptions)?
And, anything else I need to pay attention to?
Best Regards
JIA
Welcome to Vision Open
http://www.visionopen.com
Alright, I got it .
Remove
Qt Code:
pixmap.fill(Qt::transparent);To copy to clipboard, switch view to plain text mode
Cheers
JIA
Welcome to Vision Open
http://www.visionopen.com
My code is producing a JPEG similar to the one you labeled "obtained" above where the plot area is correct but it is black all around the border where there should be axis titles and chart titles. I removed the pixmap.fill(Qt::transparent) call, but still get the black border. What am I doing wrong?
When I use PNG format the images turn out fine.
QwtPlot doesn't fill the areas behind axes, title and legend. If you don't initialize your image (better use QImage instead of QPixmap if you want to produce jpegs or pngs ) you will see random ( here black ) pixels. Do a "pixmap.fill();" to initialize it.
And once more I recommend to use a scalable vector format like pdf or svg instead of rastered images.
Uwe
Bookmarks