JFreeChart&图片

时间:2011-03-11 12:38:06

标签: jfreechart

是否可以将图像/ BufferedImage转换为JFreeChart?

3 个答案:

答案 0 :(得分:15)

将图像转换为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 []。

现在需要从byte []创建图像。以下是这样做的。

InputStream in = new ByteArrayInputStream(obj);
BufferedImage image = ImageIO.read(in);
File outputfile = new File("image.png");
ImageIO.write(image, "png", outputfile);

图像在创建项目的地方(本地驱动器)创建。

答案 1 :(得分:15)

JfreeChart首先获取数据并使用通用ChartUtilities类或任何自定义实用程序类生成图像。

ChartUtilities.writeChartAsPNG(outputstream,getDataset(), width,height);

也许这可以帮到你:here

答案 2 :(得分:3)

JFreeChart对象用于制作图像,它不使用它们,图像也无法转换为JFreeChart对象。 请参阅:http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html