感谢您的回复。
自从您告诉我以来,我一直在尝试发短信。从某种意义上说,它仍然不起作用:现在不再抛出该异常,而是出于某种原因创建了空白图像。
所以我从这里出发:
public BarChartGenerator(org.qcri.power.ws.client.Server oServer, ServerStatistics oServerStat, List lVMs, String path) extends Applicationframe { System.setProperty("java.awt.headless", "true"); boolean headless = GraphicsEnvironment.isHeadless(); System.out.println("Headless: " + headless); Toolkit tk = Toolkit.getDefaultToolkit(); tk.beep(); // generate dataset final CategoryDataset dataset = createDataset(lVMs); setChart(createChart(oServer, oServerStat, lVMs, dataset)); // create PNG of the chart... setFilename("chart_server"+oServer.getHost()+"_"+System.currentTimeMillis()+".gif"); File fImageFile = new File(path+filename); try { ChartUtilities.saveChartAsPNG(fImageFile, chart, PowerInterface.CHART_WIDTH, PowerInterface.CHART_HEIGHT); } catch (Exception e) { e.printStackTrace(); } }
以下内容(摆脱
extends Applicationframe),并使用您给我的示例:
public BarChartGenerator(org.qcri.power.ws.client.Server oServer, ServerStatistics oServerStat, List lVMs, String path) { System.setProperty("java.awt.headless", "true"); boolean headless = GraphicsEnvironment.isHeadless(); System.out.println("Headless: " + headless); Toolkit tk = Toolkit.getDefaultToolkit(); tk.beep(); // generate dataset final CategoryDataset dataset = createDataset(lVMs); setChart(createChart(oServer, oServerStat, lVMs, dataset)); // create PNG of the chart... setFilename("chart_server"+oServer.getHost()+"_"+System.currentTimeMillis()+".gif"); try { BufferedImage bufferedImage = getChart().createBufferedImage(PowerInterface.CHART_WIDTH, PowerInterface.CHART_HEIGHT); ImageIO.write(bufferedImage, "gif", new FileOutputStream(path+getFilename())); } catch (Exception e) { e.printStackTrace(); } }
在日志中,它抱怨
ImageIO.write(bufferedImage, "gif", newFileOutputStream(path+getFilename()));给出此错误(文件在那里!):
javax.imageio.IIOException: Can't create output stream! at javax.imageio.ImageIO.write(ImageIO.java:1560) at org.qcri.power.util.BarChartGenerator.<init>(BarChartGenerator.java:106)
有什么线索吗?
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)