How can I write a GIF image?
Created Jan 12, 2006
John Zukowski Patent restrictions didn't allow a GIF writer to be part of the Java platform prior to JDK 6. With the recent expiration of the Unisys patent, JDK 6 includes support.
import javax.imageio.*;
import java.io.*;
import java.awt.image.*;
import java.util.*;
public class ToGif {
public static void main(String args[]) throws IOException {
if (args.length == 0) {
System.err.println("Missing input filename");
System.exit(-1);
}
String name = args[0];
File inputFile = new File(name);
BufferedImage input = ImageIO.read(inputFile);
File outputFile = new File(name+".gif");
ImageIO.write(input, "GIF", outputFile);
}
}