Encode as GIF
Encode as GIF
Hey folks,
first and foremost: JFreeChart is a great piece of work! Really a nice tool!
I have found several postings regarding the encoding in the GIF format, but they don't really help me so far (I'm still a newbie ).
The Problem is: JPEG just offers inadequate quality and PNG doesn't work on all used Browsers as it seems. (all my stuff is done in a Servlet)
I've read about the Acme-Encoder, Buffered Image and ChartUtilities, but I just can't put all these pieces together.
Can I have a sample code, please?! Just don't know how to get started.
first and foremost: JFreeChart is a great piece of work! Really a nice tool!
I have found several postings regarding the encoding in the GIF format, but they don't really help me so far (I'm still a newbie ).
The Problem is: JPEG just offers inadequate quality and PNG doesn't work on all used Browsers as it seems. (all my stuff is done in a Servlet)
I've read about the Acme-Encoder, Buffered Image and ChartUtilities, but I just can't put all these pieces together.
Can I have a sample code, please?! Just don't know how to get started.
Sample code
Here is the code I can propose to you, it works fine on Windows
It uses GifEncoder from Acme
JFreeChart chart = ChartFactory.createPieChart("MyPie", data, true,false,false);
BufferedImage bi = chart.createBufferedImage(200,200,BufferedImage.TYPE_BYTE_INDEXED, null);
try
{
// encode the image as a GIF
OutputStream output = new BufferedOutputStream( new FileOutputStream("toto.gif"));
GifEncoder encode = new GifEncoder(bi,output,true);
encode.encode();
}
catch(IOException ioe)
{
System.out.println(ioe);
}
Excuse for my english
It uses GifEncoder from Acme
JFreeChart chart = ChartFactory.createPieChart("MyPie", data, true,false,false);
BufferedImage bi = chart.createBufferedImage(200,200,BufferedImage.TYPE_BYTE_INDEXED, null);
try
{
// encode the image as a GIF
OutputStream output = new BufferedOutputStream( new FileOutputStream("toto.gif"));
GifEncoder encode = new GifEncoder(bi,output,true);
encode.encode();
}
catch(IOException ioe)
{
System.out.println(ioe);
}
Excuse for my english
ChartUtilities
In fact, to extend ChartUtilities with new encoding U can (and the simpliest way it is) copy such methods like writeChartAsPng, saveChartAsPNG,writeBufferedImageAsPNG (and somehow writeImageMap).
Although,first 3 of them are simple interfaces to encoding, the last one does the work. So there must be a code to do GIF output. I've tried some GIFEncoders, but everywhere was stuck on too large colormap. (Acme and a couple of others). Dont know how to overcome.
Although,first 3 of them are simple interfaces to encoding, the last one does the work. So there must be a code to do GIF output. I've tried some GIFEncoders, but everywhere was stuck on too large colormap. (Acme and a couple of others). Dont know how to overcome.
Re: Encode as GIF
As far as my experiments goes, i've managed to save chart as GIF using Acme Encoder and Encoder by Adam Dopplet. But yet it has too many bugs. for example it does the background to be no truly white but covered with angled dotted lines. It makes gif compression be twice larger than png compresion from that file. I guess its due to encoders algorythm.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
GIF only supports 256 colors as far as I know, which is easily exceeded if you generate charts with anti-aliasing turned on. Switch off antialiasing to avoid problems.
Unisys holds patents that prevent GIF from being freely used, which is why JFreeChart doesn't include a GIF encoder:
http://www.unisys.com/about__unisys/lzw
PNG is a free and open format that was created in response to the GIF patent problem:
http://www.w3.org/TR/PNG/
PNG is superior to GIF in almost every respect. The only problem with PNG is that Microsoft have not provided decent support for PNG in their crappy web browser. Solution: change browser.
Unisys holds patents that prevent GIF from being freely used, which is why JFreeChart doesn't include a GIF encoder:
http://www.unisys.com/about__unisys/lzw
PNG is a free and open format that was created in response to the GIF patent problem:
http://www.w3.org/TR/PNG/
PNG is superior to GIF in almost every respect. The only problem with PNG is that Microsoft have not provided decent support for PNG in their crappy web browser. Solution: change browser.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
The LZW Patent has expired
According to this:
http://www.unisys.com/about__unisys/lzw
The LZW patents have expired everywhere in the world now. It should be safe to add GIF producing code to this library.
http://www.unisys.com/about__unisys/lzw
The LZW patents have expired everywhere in the world now. It should be safe to add GIF producing code to this library.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Not quite...it says July 7, 2004 for Canada.
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
Funny, I've never had any problems viewing PNGs in IE (IE6).david.gilbert wrote:The only problem with PNG is that Microsoft have not provided decent support for PNG in their crappy web browser. Solution: change browser.
And I like PNG, and it is a wonderful format, but the filesize is usually rather large compared to gifs, so that's why people still tend to stick to gifs over png.
-
- JFreeChart Project Leader
- Posts: 11734
- Joined: Fri Mar 14, 2003 10:29 am
- antibot: No, of course not.
- Contact:
Try an image with alpha transparency. It is broken.Anonymous wrote:Funny, I've never had any problems viewing PNGs in IE (IE6).
That is false. From the W3C website:Anonymous wrote:...the filesize is usually rather large compared to gifs, so that's why people still tend to stick to gifs over png.
"PNG also compresses better than GIF in almost every case (5% to 25% in typical cases)."
Here is the link: http://www.w3.org/QA/Tips/png-gif
David Gilbert
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program
JFreeChart Project Leader
Read my blog
Support JFree via the Github sponsorship program