Creating image without saving it

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
gotti
Posts: 6
Joined: Sun May 02, 2004 2:22 pm

Creating image without saving it

Post by gotti » Tue May 25, 2004 1:58 pm

Hi,
i want to create an image out of a chart without saving it directly. My intention is to add it as an image to a pdf-file. I dont want to write it directly to a pdf because i want to handle the "positioning" somewhere else in the code.
Regards
Tobias

Guest

Post by Guest » Tue May 25, 2004 5:06 pm

You want to hold the image in memory as a buffered image :

Code: Select all

bufferedImage = chart.createBufferedImage(width, height);
then when you want the image

Code: Select all

ChartUtilities.writeBufferedImageAsPNG(out, bufferedImage);
Hope this helps

Ian

aaa
Posts: 19
Joined: Thu Jul 03, 2008 3:12 pm

Post by aaa » Tue Jul 08, 2008 12:31 pm

Guest wrote:You want to hold the image in memory as a buffered image :

Code: Select all

bufferedImage = chart.createBufferedImage(width, height);
then when you want the image

Code: Select all

ChartUtilities.writeBufferedImageAsPNG(out, bufferedImage);
Hope this helps

Ian
hi Ian

Some how i am also in similar case, but i dont want to write
but i wanted to show it in html ,<img> tag from the buffer
can i get help from you?

Regards
Vaaji

david.gilbert
JFreeChart Project Leader
Posts: 11734
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

Post by david.gilbert » Tue Jul 08, 2008 2:51 pm

Call response.getOutputStream() on the HttpServletResponse. Then do something like this:

Code: Select all

response.setContentType("image/png");
ChartUtilities.writeChartAsPNG(out, chart, 400, 300);
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Support JFree via the Github sponsorship program

aaa
Posts: 19
Joined: Thu Jul 03, 2008 3:12 pm

Post by aaa » Wed Jul 09, 2008 12:31 pm

thank you dave!

Regards
Vaaji

Locked