Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
Questions
Comments

Convert Image Formats

                         

In this example we are converting image of any format into jpg format.

Import  java.io.*  package and class  javax.imageio.ImageIO and java.awt.BufferedImage. The package  java.io.* is used for input and output operations through data streams, serialization and the file system. Classes  ImageReader and ImagrWriter  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. 

The methods used in this example are:
write(RenderedImage im, String formatName, File output): This method is used to write an image. This method takes three parameters first one is Renderedimage, second is format in which the image is to be converted and last is name of the file on which the image is to be writen. The format name may be gif, jpg, png etc.

read(File input) : This is used to read an image. 

Code Description:

This example 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.

Here is the code of the program :

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

}
}

 Input on DOS Prompts :

C:\image>javac GIFToJPG.java
C:\image>java GIFToJPG
Enter image name
rajeshxml2.gif
Enter the output image name(.jpg):
raju.jpg
Your image has been converted successfully

Input image:rajeshxml2.gif

Output of The Example:raju.jpg


Download this example.

                         

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Latest Searches:
Jframe Tutorials
parse string to value
Linux Administration L
Date compare in JSP
heap sorting
message box display in
periodic table java ap
s?????????????????????
runnable interface
jdbc mysql connection
property
Combattons la programm
Convert a ASCII into t
Xml parsing using serv
x509
BigInteger
mysql connector
text box in swind
retrive data from data
buffer
server side javascript
stored procedure dubg
struts.xml <param name
create file menu using
Web Messenger in java
index jstl
File Stream
jboss connection pool
write a xml file using
how to use the selecti
filesclass,java
String based programme
insert calendar in jsp
Html tag inside out im
get and set methods in
java date compare exam
userid
free java networking t
create a directory
PHP Date and time func
postgre
submit button in Frame
servlets programming
<sql-query
parse string data
CSS min-height Interne
Haspmap
java file colum
validator
count row in resultset
constructor without pa
ComboBox in java
Creating a text editor
connection bean
jsf and database manip
radio button in html
lookupDispatchAction i
validate radio button
File
insert data to text fi
request.getQueryString
J-Integra Excel exampl
java button event fram
how to save the passwo
CREATING TABLE
Eclipse 3.4 EJB
char at
input in java
jquery using .net 2.0
input in array
struts.jar download
jsp Insert insert data
code for session bean
array sum
StringBuffer
FileInputStream
multiple log files
parse string in java
airplane seating
JSTL API
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.