I converted an applet that displays a graphics to a servlet using the Acme Gif encoder. Why do the graphics look so poor now?

Alessandro A. Garbagnati

Hi,
It is possible that the loss of quality it's done in the conversion to a GIF. Remember that that format only allows 256 colors and I don't know how the color reduction it's done.
I've used that encoder few times for generating charts, where the number of color was limited. But I prefer to generate jpeg images using the jpeg encoder that it's now part of the Java 2 distribution, and it's way fater than the GIF Encder:

import com.sun.image.codec.jpeg.*;
...
...
BufferedImage image = ... your image ...;
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image);
...

You can even control the jpeg quality with the JPEGEncodeParam, just altering a little the above example:

JPEGEncodeParam eP = JPEGCodec.getDefaultJPEGEncodeParam(image);
eP.setQuality(1.0f, true);
BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
encoder.encode(image, eP);

If the result satisfy you, then probably the problem it's really in the reduction of the number of colors.

[See also http://www.jguru.com/faq/view.jsp?EID=159 -Alex]

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact