2014-09-11 2 views
0

Я пробовал код для сохранения найденных файлов png here, и он работает. Но я хочу, чтобы сохранить векторное изображение, поэтому я сменил терминал на: PostscriptTerminal и SVGTerminal. Для SVGTerminal выхода в пустой и когда я использую PostscriptTerminal код висит на p.plot();Как сохранить файл svg или esp в JavaPlot

ImageTerminal png = new ImageTerminal(); 
    PostscriptTerminal eps = new PostscriptTerminal(); 
    SVGTerminal svg = new SVGTerminal(); 

    File file = new File("D:/plot.eps"); 
    try { 
     file.createNewFile(); 
     eps.processOutput(new FileInputStream(file)); 
    } catch (FileNotFoundException ex) { 
     System.err.print(ex); 
    } catch (IOException ex) { 
     System.err.print(ex); 
    } 

    PlotStyle myPlotStyle = new PlotStyle(); 
    myPlotStyle.setStyle(Style.POINTS); 
    myPlotStyle.setPointType(7); // 7 - circle 
    myPlotStyle.setLineType(3); // blue color 

    JavaPlot p = new JavaPlot(); 
    p.setPersist(false); 
    p.setTerminal(eps); 
    //p.setTitle(algorithm_name+" - "+problem_name, "Arial", 20); 
    p.getAxis("x").setLabel("X axis", "Arial", 15); 
    p.getAxis("y").setLabel("Y axis","Arial", 15); 
    p.setKey(JavaPlot.Key.TOP_RIGHT); 

    double[][] front = this.writeObjectivesToMatrix(); 
    DataSetPlot s = new DataSetPlot(front); 
    s.setPlotStyle(myPlotStyle); 
    s.setTitle(""); 
    p.addPlot(s); 
    p.plot(); //code hangs here if I use PostscriptTerminal 

    try { 
     //ImageIO.write(png.getImage(), "png", file); //works 
     BufferedWriter writer = new BufferedWriter(new FileWriter(file)); 
     writer.write (eps.getTextOutput()); 
     //Close writer 
     writer.close(); 
    } catch (IOException ex) { 
     System.err.print(ex); 
    } 

ответ

0

мне удалось сохранить файл .eps. Мне нужно было только добавить путь к файлу в конструкторе, и он сработал.

PostscriptTerminal eps = new PostscriptTerminal("output.eps"); 

    PlotStyle myPlotStyle = new PlotStyle(); 
    myPlotStyle.setStyle(Style.POINTS); 
    myPlotStyle.setPointType(7); // 7 - circle 
    myPlotStyle.setLineType(3); // blue color 

    JavaPlot p = new JavaPlot(); 
    p.setPersist(false); 
    p.setTerminal(eps); 
    p.getAxis("x").setLabel("X axis", "Arial", 15); 
    p.getAxis("y").setLabel("Y axis","Arial", 15); 
    p.setKey(JavaPlot.Key.TOP_RIGHT); 

    double[][] front = this.writeObjectivesToMatrix(); 
    DataSetPlot s = new DataSetPlot(front); 
    s.setPlotStyle(myPlotStyle); 
    s.setTitle(""); 
    p.addPlot(s); 
    p.plot(); 
Смежные вопросы