PDA

View Full Version : I cannot save a Surface plot as JPEG file



locke
13th August 2010, 12:48
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



QString types( "JPEG file (*.jpeg);;"
"Portable Network Graphics file (*.png);;"
"Bitmap file (*.bmp)");


QString filter;

QString jpegExt=".jpeg", pngExt=".png", bmpExt=".bmp";

QString suggestedName = "";

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

Lykurg
13th August 2010, 13:19
Are you sure you have the needed image plugin for jpeg? (see caption "Qt Plugins" in "Deploying an Application on Windows" at the documentation)

locke
13th August 2010, 13:45
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.

locke
13th August 2010, 15:33
Another curious thing is that I can save QwtPlots (2D plots) in jpeg only if I am running in Debug mode. What could happend?

Lykurg
13th August 2010, 15:55
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...

locke
13th August 2010, 16:19
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

locke
13th August 2010, 16:35
This is the code


QImage px;
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.

Uwe
13th August 2010, 17:25
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

locke
16th August 2010, 09:03
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?

Uwe
16th August 2010, 09:41
No it means that an application in release mode can't load a plugin in debug mode ( or v.v ).

Uwe

locke
16th August 2010, 09:49
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.

ramzes13
21st September 2010, 13:07
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.

wysota
21st September 2010, 14:26
Is your question related to Qwt? If not, why are you hijacking the thread?

http://www.qtcentre.org/faq.php?faq=qt_images#faq_qt_missing_images

ramzes13
21st September 2010, 15:12
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.