Java Graphics How to - Convert bmp image to GIF image








Question

We would like to know how to convert bmp image to GIF image.

Answer

// w  w  w  .ja  va  2 s. com
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;

public class ImageConverterGIF {
  public static void main(String[] args) throws Exception {
    String imageFilePath = "C:/myBmp.bmp";
    String gifFilePath = "C:/myPic.gif";
    File inputFile = new File(imageFilePath);
    BufferedImage image = ImageIO.read(inputFile);
    File outputFile = new File(gifFilePath);
    ImageIO.write(image, "GIF", outputFile);
  }
}