© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

Convert Image formats to JPEG format Using Java

Description:

This program is to convert an image of any format into jpg format. It reads the image name passed at the command prompt for converting the image into the jpg format. In this example we are reading the image from system by using read () method of ImageIO class. We are using write () method for conversion of an image of any format into the jpg format.

The package java.io.* is used for input and output operations through data streams, serialization and the file system. Classes ImageReader and ImageWriter inherit the static methods from the class javax.imageio. ImageIO for reading and writing the images respectively. The class java.awt.BufferedImage extends Image class and implements WritableRenderedImage interface. The class BufferedImage is used to access an image. Write () method has input image, the format which is to be converted and the output image as the parameters. This method converts image of any format into jpg.

Convert Image formats to JPEG format Using Java :

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()); } } }

Sample ScreenShot:

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom