Bad color spots when downsizing GIF images

B

bonkura_

I am having quality problems with resized gif images. I wish to resize
images down to sizes between 100x100 and 200x200 from larger images but
the quality is not acceptable.

the quality of the image is fine if I just load it and write it back to
disk without resizing or if I load it using Gif4j as a GifImage object
and resize it with the gif4j GifTransformer class. If I resize in any
other way I get a very bad quality image, basically the problem is with
the colors in that an area witch in the original size image had one
color has maybe 2-3 colors in the resized image, making the image look
very bad. The code I use works fine for resizing images of other
formats such as jpeg.

I wonder if it is related to the use of indexedcolormodel in the gif
images? I am wondering if there is another way to resize or some
special processing I can add to make it work for gif.

Below is the code I currently use for resizing, I started to use
AreaAveragingScaleFilter because other methods did not produce
acceptable quality for jpeg images.

private static BufferedImage resizeImage(BufferedImage inImage,double
scale){
int newWidth = (int) (inImage.getWidth() * scale);
int newHeight = (int) (inImage.getHeight() * scale);
int type = inImage.getType();

if(type == 0){
type = BufferedImage.TYPE_INT_RGB;
}
AreaAveragingScaleFilter aasfilter = new
AreaAveragingScaleFilter(newWidth, newHeight);

FilteredImageSource fisource = new
FilteredImageSource(inImage.getSource(), aasfilter);

Image image2 =
Toolkit.getDefaultToolkit().createImage(fisource);

BufferedImage theNewImage2 = new BufferedImage( newWidth,
newHeight, type );
Graphics2D g2 = theNewImage2.createGraphics();

g2.setComposite(AlphaComposite.Src);
g2.drawImage(image2, 0, 0, null);
g2.dispose();

return theNewImage2;
}

Appreciate any ideas on this...
 
R

Roedy Green

I am having quality problems with resized gif images. I wish to resize
images down to sizes between 100x100 and 200x200 from larger images but
the quality is not acceptable.

You must shrink by powers of two to get acceptable quality with gif.
For smooth scaling, try jpg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top