Encode as GIF

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
Ooschn

Encode as GIF

Post by Ooschn » Wed May 26, 2004 7:04 am

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 :shock:).
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.

jpverdu

Sample code

Post by jpverdu » Wed May 26, 2004 1:11 pm

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

iogan18tm
Posts: 24
Joined: Tue May 04, 2004 5:14 pm

ChartUtilities

Post by iogan18tm » Wed May 26, 2004 1:32 pm

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.

Guest

Re: Encode as GIF

Post by Guest » Wed May 26, 2004 5:38 pm

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.

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 » Thu May 27, 2004 9:04 am

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.
David Gilbert
JFreeChart Project Leader

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

MojoRilla

The LZW Patent has expired

Post by MojoRilla » Mon Jun 21, 2004 7:32 pm

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.

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 » Mon Jun 21, 2004 7:42 pm

Not quite...it says July 7, 2004 for Canada.
David Gilbert
JFreeChart Project Leader

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

Guest

Post by Guest » Mon Jun 21, 2004 8:31 pm

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.
Funny, I've never had any problems viewing PNGs in IE (IE6).
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.

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 » Mon Jun 21, 2004 10:02 pm

Anonymous wrote:Funny, I've never had any problems viewing PNGs in IE (IE6).
Try an image with alpha transparency. It is broken.
Anonymous wrote:...the filesize is usually rather large compared to gifs, so that's why people still tend to stick to gifs over png.
That is false. From the W3C website:

"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

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

Locked