PDA

View Full Version : how to save the QImage file in the desired directory location?



mammaiap
24th March 2011, 13:17
Hi Friends,

i wanted to save the QImage file into the desired directory....i have changed the directory and save the QImage... but it is not saving into the desired directory.....it saves into the application current directory....

here is my code snippet:


QDir *dir = new QDir(".");
if( dir->cd("LSWT_Report"));
if(dir->cd("Report"));
if(dir->cd("Plots"));

const double scaleFactor = 3.0;
const QSize sz(3543, 2362);

QImage image(sz, QImage::Format_ARGB32);
image.fill( QColor( Qt::white ).rgb() );

QPainter painter(&image);
painter.scale(scaleFactor, scaleFactor);

QwtPlotRenderer renderer;

QString saveFileName;

for(int j=0;j<plots.count();j++)
{
if(j==0)
{
saveFileName = "CdVsCl.png";
}
if(j==1)
{
saveFileName = "AOAVsCl.png";
}
if(j==2)
{
saveFileName = "AOAVsCm.png";
}
if(j==3)
{
saveFileName = "AOAVsCd.png";
}
if(j==4)
{
saveFileName = "ClVsClbyCd.png";
}
if(j==5)
{
saveFileName = "AOAVsClbyCd.png";
}

renderer.render(plots.at(j), &painter, QRectF( QPointF(0, 0), sz / scaleFactor ) );

image.save( saveFileName );

}

please anyone can help me.....

Thanks in Advance,
Muthu

high_flyer
24th March 2011, 14:05
Why do you put your cd's in if statements if you are not evaluating the results??
Also, if you are hard coding the directories to change to, you can just as well put it in one path setting.
But since you are NOT using the dir variable don't need it!
And, you are giving QImage only the image name:


...
saveFileName = "CdVsCl.png";
...
image.save( saveFileName );

So no woder it gets saved to the working directory.

Try this code:


//This whole block of code is doing nothing !! get rid of it!
//QDir *dir = new QDir(".");
// if( dir->cd("LSWT_Report"));
// if(dir->cd("Report"));
// if(dir->cd("Plots"));

//chaneg your saving line to:
image.save( ".\\LSWT_Report\\Report\\Plots\\"+saveFileName );

mammaiap
25th March 2011, 05:19
Thanks for your reply....

it works as per the expectation...