Results 1 to 3 of 3

Thread: how to save the QImage file in the desired directory location?

  1. #1
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Question how to save the QImage file in the desired directory location?

    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:
    Qt Code:
    1. QDir *dir = new QDir(".");
    2. if( dir->cd("LSWT_Report"));
    3. if(dir->cd("Report"));
    4. if(dir->cd("Plots"));
    5.  
    6. const double scaleFactor = 3.0;
    7. const QSize sz(3543, 2362);
    8.  
    9. QImage image(sz, QImage::Format_ARGB32);
    10. image.fill( QColor( Qt::white ).rgb() );
    11.  
    12. QPainter painter(&image);
    13. painter.scale(scaleFactor, scaleFactor);
    14.  
    15. QwtPlotRenderer renderer;
    16.  
    17. QString saveFileName;
    18.  
    19. for(int j=0;j<plots.count();j++)
    20. {
    21. if(j==0)
    22. {
    23. saveFileName = "CdVsCl.png";
    24. }
    25. if(j==1)
    26. {
    27. saveFileName = "AOAVsCl.png";
    28. }
    29. if(j==2)
    30. {
    31. saveFileName = "AOAVsCm.png";
    32. }
    33. if(j==3)
    34. {
    35. saveFileName = "AOAVsCd.png";
    36. }
    37. if(j==4)
    38. {
    39. saveFileName = "ClVsClbyCd.png";
    40. }
    41. if(j==5)
    42. {
    43. saveFileName = "AOAVsClbyCd.png";
    44. }
    45.  
    46. renderer.render(plots.at(j), &painter, QRectF( QPointF(0, 0), sz / scaleFactor ) );
    47.  
    48. image.save( saveFileName );
    49.  
    50. }
    To copy to clipboard, switch view to plain text mode 

    please anyone can help me.....

    Thanks in Advance,
    Muthu
    Last edited by high_flyer; 24th March 2011 at 13:53. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: how to save the QImage file in the desired directory location?

    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:
    Qt Code:
    1. ...
    2. saveFileName = "CdVsCl.png";
    3. ...
    4. image.save( saveFileName );
    To copy to clipboard, switch view to plain text mode 
    So no woder it gets saved to the working directory.

    Try this code:
    Qt Code:
    1. //This whole block of code is doing nothing !! get rid of it!
    2. //QDir *dir = new QDir(".");
    3. // if( dir->cd("LSWT_Report"));
    4. // if(dir->cd("Report"));
    5. // if(dir->cd("Plots"));
    6.  
    7. //chaneg your saving line to:
    8. image.save( ".\\LSWT_Report\\Report\\Plots\\"+saveFileName );
    To copy to clipboard, switch view to plain text mode 
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2010
    Posts
    28
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: how to save the QImage file in the desired directory location?

    Thanks for your reply....

    it works as per the expectation...

Similar Threads

  1. save Qimage in a file
    By OverTheOCean in forum Qt Programming
    Replies: 7
    Last Post: 21st March 2011, 00:42
  2. Replies: 6
    Last Post: 5th December 2009, 15:46
  3. QIcon Directory Location
    By QbelcorT in forum Qt Tools
    Replies: 4
    Last Post: 28th January 2009, 02:06
  4. Can't save QImage
    By hvengel in forum Qt Programming
    Replies: 6
    Last Post: 14th June 2008, 22:07
  5. Replies: 3
    Last Post: 15th March 2006, 12:44

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.