Results 1 to 14 of 14

Thread: I cannot save a Surface plot as JPEG file

  1. #1
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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
    Qt Code:
    1. QString types( "JPEG file (*.jpeg);;"
    2. "Portable Network Graphics file (*.png);;"
    3. "Bitmap file (*.bmp)");
    4.  
    5.  
    6. QString filter;
    7.  
    8. QString jpegExt=".jpeg", pngExt=".png", bmpExt=".bmp";
    9.  
    10. QString suggestedName = "";
    11.  
    12. QString fn = QFileDialog::getSaveFileName(0, tr("Save 3D Plot"), QDir::homePath()+ "/" +suggestedName, types, &filter);
    13.  
    14. // If filename is not a null
    15. // Remove file extension if already there
    16. if ( !fn.isEmpty() )
    17. {
    18. if (fn.contains(jpegExt))
    19. {
    20. fn.remove(jpegExt);
    21. }
    22. else if (fn.contains(pngExt))
    23. {
    24. fn.remove(pngExt);
    25. }
    26. else if (fn.contains(bmpExt))
    27. {
    28. fn.remove(bmpExt);
    29. }
    30.  
    31. if (filter.contains(pngExt))
    32. {
    33.  
    34. fn+=pngExt;
    35. IO::save(m_3dPlot, fn, "png" );
    36. }
    37. else if (filter.contains(jpegExt))
    38. {
    39.  
    40. fn+=jpegExt;
    41. IO::save(m_3dPlot, fn, "jpeg" );
    42. }
    43. else if (filter.contains(bmpExt))
    44. {
    45.  
    46. fn+=bmpExt;
    47. IO::save(m_3dPlot, fn, "bmp" );
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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)

  3. The following user says thank you to Lykurg for this useful post:

    locke (16th August 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  5. #4
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default 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...

  7. #6
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  8. #7
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: I cannot save a Surface plot as JPEG file

    This is the code
    Qt Code:
    1. QImage px;
    2. px.load("input.jpeg");
    3. px.save("output.jpeg");
    To copy to clipboard, switch view to plain text mode 
    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.

  9. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  10. The following user says thank you to Uwe for this useful post:

    locke (16th August 2010)

  11. #9
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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?

  12. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default 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

  13. #11
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

  14. #12
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Last edited by ramzes13; 21st September 2010 at 13:18.

  15. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #14
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.

Similar Threads

  1. How to save a plot as .jpg..
    By jiapei100 in forum Qwt
    Replies: 5
    Last Post: 4th February 2010, 06:41
  2. Save pictures in JPEG format into QDataStream
    By Eos Pengwern in forum Qt Programming
    Replies: 2
    Last Post: 31st December 2009, 13:14
  3. Replies: 11
    Last Post: 31st December 2008, 12:30
  4. cannot save QPixmap as jpeg
    By arunredi in forum Qt Programming
    Replies: 1
    Last Post: 16th May 2008, 08:42
  5. Replies: 32
    Last Post: 30th March 2008, 20:00

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.