0% found this document useful (0 votes)
24 views

Java Pgm17

Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Java Pgm17

Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Ex No.

27
Date:
Image Conversion
Aim:
To write a java program to convert a GIF image To JPEG Image.
Source Code:
import java.io.*;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class GIFToJPG
{
public static void main(String a[]){
try{
System.out.println("Enter image name\n");
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
String imageName=bf.readLine();
File input = new File(imageName);
BufferedImage image = ImageIO.read(input);
System.out.println("Enter the output image name(.jpg):\n");
String imageName1=bf.readLine();
File output = new File(imageName1);
ImageIO.write(image, "jpg", output);
System.out.println("Your image has been converted successfully");
}catch(FileNotFoundException e){
System.out.println("Error:"+e.getMessage());
}catch(IOException e)
{
System.out.println("Error:"+e.getMessage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}
Output:
javac GIFToJPG.java
java GIFToJPG
Enter image name
rajeshxml2.gif
Enter the output image name(.jpg):
raju.jpg
Your image has been converted successfully

Result:
Thus a java program has been written to convert the image format.

You might also like