Hmm, just realised that you asked for how to reduce the size of an ANIMATED GIF... AFAIK the individual images that make up a GIF animation are basically listed after each other in the file. You should be able to read and render each individual frame/image and scale them individually, then reassemble them for output. You will still have to solve the problem with a GIF encoder.
Main Topics
Browse All Topics





by: orangehead911Posted on 2006-11-14 at 03:39:29ID: 17937302
If the image is larger than 100kb, read it in using the ImageIO class. The call getScaledInstance on the BufferedImage received from calling the read method on ImageIO. Calculate the scaling factor using the code below;
int width = image.getWidth();
int height = image.getHeight();
int desiredWidth = (int) (width / ((double) file.length() / 1024) * DESIRED_FILE_SIZE_IN_KB);
int desiredHeight = (int) (height / ((double) file.length() / 1024) * DESIRED_FILE_SIZE_IN_KB);
Only one problem remains; there is no GIF encoder available in the JDK or the JRE. You have to either save as a different file format (I recommend PNG), or you have to license a GIF encoder.