Casting an image in JFree is not possible. 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 a byte [].
Now you need to create an image from byte []. This does the following.
InputStream in = new ByteArrayInputStream(obj); BufferedImage image = ImageIO.read(in); File outputfile = new File("image.png"); ImageIO.write(image, "png", outputfile);
The image is created at the project creation location (local disk).
source share