Saving plot as jpeg-file does not work

Help
2009-10-21
2013-03-15
  • Stefan Kummer
    Stefan Kummer
    2009-10-21

    Hello,
    I tried to save a plot as a jpeg-file: "plotwindow->SavePlot(wxT("jpeg"), filename);" but it fails (applicaton aborts). Using png-file format works fine: "plotwindow->SavePlot(wxT("png"), filename);". I've also tried to use wxT("jpg") but without success. Do I have to enable a jpeg-driver or something like this?

    Regards
    Stefan

     
  • Werner Smekal
    Werner Smekal
    2009-10-21

    Hi,

    you're using the wxPLplotwindow class, do you? I just had a look at it, and this method is using the driver/devices provided by PLplot (the wxwidgets driver could also use the image output formats provided by wxWidgets, but this will be added in later releases). Anyway, the png and jpeg driver are provided by the gd driver (using libgd). Since png output works I assume, that the gd driver is compiled by cmake, but somehow not the jpeg device turned on. After you run cmake, there is some output (summary) of all important flags and there is also a list of all drivers enabled and devices provided. Could you have a look there, if jpeg (and gd) is one of them?

    Thanks,
    Werner

     
  • Stefan Kummer
    Stefan Kummer
    2009-10-22

    Hi Werner,

    yes I'm using the wxPlplotwindow class. Here is a part of the cmake-output:

    "ENABLE_DYNDRIVERS: ON

    DRIVERS_LIST: cairo;cgm;qt;hpgl;mem;null;pbm;ps;svg;wxwidgets;xfig;xwin

    DEVICES_LIST: extcairo;pdfcairo;pngcairo;pscairo;svgcairo;xcairo;cgm;epsqt;pdfqt;qtwidget;bmpqt;
    jpgqt;pngqt;ppmqt;tiffqt;extqt;svgqt;hp7470;hp7580;lj_hpgl;mem;null;pbm;ps;svg;wxwidgets;xfig;xwin".

    But I can not see why png-driver works and jpeg-driver not.

    Regards Stefan

     
  • Werner Smekal
    Werner Smekal
    2009-10-22

    Hi,

    that's actually quite strange. You don't have even the gd driver included, so the png device shouldn't work as well. Anyway, the wxwidgets driver itself has already a better SavePlot function, the bindings could be enhanced accordingly. Copy the SavePlot() function from drivers/wxwidgets_app.cpp (line 353) to bindings/wxPlplotwindow.cpp and also change wxPlplotwindow.h accordingly. This function uses the available imagehandler provided by wxWidgets to save the plot. So you got a lot of options (btw, actually you shouldn't use jpeg for plots, since the quality sucks, png i lossless here and much better). You must recompile plplot then. I'll do the same for the latest svn, but this might take a while and it should work by just doing this small changes. It might error out if you use a wrong devicename (and close you application), this will be addressed in my changes.

    HTH,
    Werner

     
  • Stefan Kummer
    Stefan Kummer
    2009-10-23

    Hi Werner,

    I have done the changes you proposed and jpg-output basically works. But there remain some problems. For example in my plot I changed the backgroundcolor to white an the jpg-output still keeps the default color black. Perhaps I can solve those problems. Thank you very much.

    Regards Stefan

     
  • Werner Smekal
    Werner Smekal
    2009-10-23

    You could add plclear() at the beginning of your plot. I'm not sure right now, if plreplot() also "remembers" plclear() calls, but you could try. Problem is, that the canvas is cleared in plbop() which is not called if you replot the buffer. Alternatively you could clear the background yourself in background color in Saveplot(). This is a hack, but I'm working on plplot buffer improvements. Needs some time.

    Regards,
    Werner