【问题标题】:JFreeChart & ImageJFreeChart & Image
【发布时间】:2011-03-11 12:38:05
【问题描述】:

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

【问题讨论】:

  • 您想将图像投射/转换为图表吗?我不明白这可能如何工作
  • 你想用 Jfreechart 制作图像/BufferedImages 吗?

标签: jfreechart


【解决方案1】:

无法将图像投射到 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);

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

【讨论】:

  • 从 JFreeChart 创建图像的另一种方法是使用 ChartUtilities.writeChartAsPNG(ouputstream,jfreechart,x,y) 函数。
  • yannis hristofakis:这样,您就无法访问 BufferedImage。我需要这个,因为图表添加了一些我无法通过配置图表来消除的填充,所以我不得不裁剪图像 - BufferedImage.getSubImage(...)
【解决方案2】:

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

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

也许这可以帮助你:here

【讨论】:

    【解决方案3】:

    JFreeChart 对象用于制作图像,它不消耗图像并且图像不能转换为 JFreeChart 对象。 见:http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

    【讨论】:

      猜你喜欢
      • 2013-11-18
      • 1970-01-01
      • 2016-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-26
      相关资源
      最近更新 更多