tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Java > Image IO > How to change image type

How to change image type 

Java Image IO provides pluggable architecture for accessing images transparently. It is simple, flexible and allows us to plugin various image readers and writers with ease. The following example shows image conversion among various formats.

stpatricks_08.gif

File Name  :  
com/bethecoder/tutorials/imageio/ChangeImageTypeTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.imageio;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;

public class ChangeImageTypeTest {

  /**
   @param args
   @throws IOException 
   */
  public static void main(String[] argsthrows IOException {

    URL url = new URL("http://www.google.com/logos/2008/stpatricks_08.gif");
    BufferedImage bufImage = ImageIO.read(url);

    //Convert the image to following formats [bmp, jpg, png, gif]
    for (String imageTypeSuffix : new String [] { "bmp""jpg""png""gif" }) {
      ImageIO.write(
          bufImage, imageTypeSuffix, 
          new File("C:/Temp/downloaded_image." + imageTypeSuffix));
    }
  }

}
   

It gives the following output,

downloaded_image.bmp
downloaded_image.gif
downloaded_image.jpg
downloaded_image.png


                    Print

   



Books Recommendation

 
 
bl  br