JFreeChart & Image

后端 未结 3 1404
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-13 00:06

Is it possible to cast an image/BufferedImage to JFreeChart?

相关标签:
3条回答
  • 2021-01-13 00:59

    JfreeChart takes data first and generate image using generic ChartUtilities class or any customized utility class.

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

    Maybe this can help you:here

    0 讨论(0)
  • 2021-01-13 01:00

    The JFreeChart object is for making images, it does not consume them and images cannot be converted into a JFreeChart object. See: http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/JFreeChart.html

    0 讨论(0)
  • 2021-01-13 01:04

    Casting an image to JFree is not possbile. To create an image from JFreechart you can do the following:

    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();
    

    This creates the byte[] .

    Now you need to create the image from byte[]. The following does this.

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

    The image gets created at the place where your project is created(local drive).

    0 讨论(0)
提交回复
热议问题