gifファイルの出力 2006/12/02

javaプログラムから gifファイルを出力する方法です。
gif-plugin
を使用しています。

サンプルコードです。

BufferedImage bufferedImage = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB);
new NeuQuantQuantizerOP().filter(bufferedImage, bufferedImage);
ImageIO.write(bufferedImage, "gif", new File("filename.gif"));


扱う imageが使用しているカラーを 調整するためNeuQuantQuantizerOPを使用しています。
使用しない場合 Too many colorでエラーとなります。
If the source image contains more than 256 colours you most likely will want to reduce the number of colours used. You can do so by using the included NeuQuantQuantizerOP

だそうです。

: