【发布时间】:2011-03-11 12:38:05
【问题描述】:
是否可以将图像/BufferedImage 转换为 JFreeChart?
【问题讨论】:
-
您想将图像投射/转换为图表吗?我不明白这可能如何工作
-
你想用 Jfreechart 制作图像/BufferedImages 吗?
标签: jfreechart
是否可以将图像/BufferedImage 转换为 JFreeChart?
【问题讨论】:
标签: jfreechart
无法将图像投射到 JFree。要从 JFreechart 创建图像,您可以执行以下操作:
BufferedImage objBufferedImage=objJFreechart.createBufferedImage(600,800);
ByteArrayOutputStream bas = new ByteArrayOutputStream();
try {
ImageIO.write(objBufferedImage, "png", bas);
} catch (IOException e) {
e.printStackTrace();
}
byte[] byteArray=bas.toByteArray();
这会创建字节[]。
现在您需要从 byte[] 创建图像。以下是这样做的。
InputStream in = new ByteArrayInputStream(obj);
BufferedImage image = ImageIO.read(in);
File outputfile = new File("image.png");
ImageIO.write(image, "png", outputfile);
图像是在您的项目创建的地方(本地驱动器)创建的。
【讨论】:
ChartUtilities.writeChartAsPNG(ouputstream,jfreechart,x,y) 函数。
JfreeChart 首先获取数据并使用通用 ChartUtilities 类或任何自定义实用程序类生成图像。
ChartUtilities.writeChartAsPNG(outputstream,getDataset(), width,height);
也许这可以帮助你:here
【讨论】:
JFreeChart 对象用于制作图像,它不消耗图像并且图像不能转换为 JFreeChart 对象。
见:http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html
【讨论】: