I cannot save a Surface plot as JPEG file
Hi,
I have a similar code to save the plot as PNG or BMP and works, but with the JPEG file it doesnt work (neigther with JPG)
Here is the code
Code:
QString types
( "JPEG file (*.jpeg);;" "Portable Network Graphics file (*.png);;"
"Bitmap file (*.bmp)");
QString jpegExt
=".jpeg", pngExt
=".png", bmpExt
=".bmp";
QString fn
= QFileDialog::getSaveFileName(0, tr
("Save 3D Plot"),
QDir::homePath()+ "/" +suggestedName, types,
&filter
);
// If filename is not a null
// Remove file extension if already there
if ( !fn.isEmpty() )
{
if (fn.contains(jpegExt))
{
fn.remove(jpegExt);
}
else if (fn.contains(pngExt))
{
fn.remove(pngExt);
}
else if (fn.contains(bmpExt))
{
fn.remove(bmpExt);
}
if (filter.contains(pngExt))
{
fn+=pngExt;
IO::save(m_3dPlot, fn, "png" );
}
else if (filter.contains(jpegExt))
{
fn+=jpegExt;
IO::save(m_3dPlot, fn, "jpeg" );
}
else if (filter.contains(bmpExt))
{
fn+=bmpExt;
IO::save(m_3dPlot, fn, "bmp" );
}
}
Any ideas? I doesnt work by changing jpeg by JPEG. Wehn I try to save the plot as jpeg file, no file is created.
Thanks
Re: I cannot save a Surface plot as JPEG file
Are you sure you have the needed image plugin for jpeg? (see caption "Qt Plugins" in "Deploying an Application on Windows" at the documentation)
Re: I cannot save a Surface plot as JPEG file
It doesnt work.
I added this to the .pro file;
QTPLUGIN += qjpeg qgif qmng # image formats
And in the file I included the <QtPlugin> header and after Q_IMPORT_PLUGIN(qjpeg);
But, it doest find Q_IMPORT_PLUGIN() .
I mesh2 of the qwtPlot3D exaples there are similar functions to save plots, and the example doesnt need to add any external plugin.
Re: I cannot save a Surface plot as JPEG file
Another curious thing is that I can save QwtPlots (2D plots) in jpeg only if I am running in Debug mode. What could happend?
Re: I cannot save a Surface plot as JPEG file
Argh, I haven't seen that you post in the qwt sub forum. I never have worked with it, but after some digging in the sources it seems to me that IO::Save support all formats QImageWriter::supportedImageFormats() provide. Is jpeg in it on your machine? And for a simple test load a jpeg file and save it right back with QImage and see if it works. If so there must be a problem in the qwt libraries, but then I am out.
EDIT: Ok, need to long to write; What's about QwtPlots in release mode?
EDIT: not my day: Seems you missing the plugin for release mode...
Re: I cannot save a Surface plot as JPEG file
I[m triying right now to do something like
qApp->addLibraryPath(myBaseDir.path() + "exe/plugins/imageformats");
and include all thje imageformats dlls in the exe directory, that will be copied to every installation machine, but It doesnt work.
I can draw a QwtPlot in Debug or Release mode. But I can only save in debug mode. I will try to load and save a jpeg file, in order to isolate the problem, and to know if its a problem from Qt or Qwt
Re: I cannot save a Surface plot as JPEG file
This is the code
Code:
px.load("input.jpeg");
px.save("output.jpeg");
In the constructor, in debug mode, the output.jpeg file is created. In relese mode, nothing is created. I dont know why, if Qt search automatically the plugins directory in its installation directory, then there is a difference between release and debug.
Re: I cannot save a Surface plot as JPEG file
On windows its always the same problem, that an application in release mode can't load a plugin in debug mode ( or v.v ). Guess you don't have a jpeg plugin, that was build in debug mode.
Uwe
Re: I cannot save a Surface plot as JPEG file
That means that all the pugin information in the documentation is only useful in debug mode. There is no way then to use the jpeg plugin in release mode?
Re: I cannot save a Surface plot as JPEG file
No it means that an application in release mode can't load a plugin in debug mode ( or v.v ).
Uwe
Re: I cannot save a Surface plot as JPEG file
C:\Qt\2010.01\qt\plugins\imageformats contains all the libarries, ( release and debug liraries for static linking (.a) and both for dinamic linkin .dll . So I dont understand why doesnt pick the library in release mode as well as in debug mode.
Re: I cannot save a Surface plot as JPEG file
Hi All,
I have a similar problem.
When I compile my program in release mode and take it to another computer
Function: QImage->save(image_name, "JPEG", 100)
returns 0
However, on my computer everything is fine.
I am using Qt Creator 2.0.0 based on Qt 4.7.0 (32 bit) (WindowsXP)
Copying jped Qt plugin in the folder with executable did not help.
Does anybody know what is the problem?
Thank you.
Re: I cannot save a Surface plot as JPEG file
Is your question related to Qwt? If not, why are you hijacking the thread?
http://www.qtcentre.org/faq.php?faq=...missing_images
Re: I cannot save a Surface plot as JPEG file
Dear wysota,
Thanks for your reply and sorry for posting in the wrong thread. I just found this topic using search and did not notice that it is only for Qwt topics.