Convert a GIF to a JPG in Java

This Java tutorial shows how to use the ImageIO API to convert a GIF to a JPG image in Java. The ImageIO API provides methods to read the source image and to write the image in the new file format.

To read the image, simply provide the method a File object for the source image. This will return a BufferedImage.

//Create file for the source
File input = new File("c:/temp/image.gif");

//Read the file to a BufferedImage
BufferedImage image =;

Once you have the BufferedImage, you can write the image as a JPG. You will need to create a File object for the destination image. When calling the write() method, specify the type string as "jpg".
//Create a file for the output
File output = new File("c:/temp/image.jpg");

//Write the image to the destination as a JPG
ImageIO.write(image, "jpg", output);


Post a Comment