Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Use of Image I/O library 
 

The ImageIO class provides the method to read and write image. We are providing you an example which copies the specified input file into the output file.

 

Use of Image I/O library

                         

This section illustrates you how to use Image I/O library.

The ImageIO class provides the method to read and write image. We are providing you an example which copies the specified input file into the output file. A file image4.jpg is defined as input file which is read by the method read() of ImageIO class and returns  a buffered image after decoding the file.

A matrix is defined in the variable data of float type. This matrix is defined by the class Kernel to describe how a pixel affect its position in the output image of a filtering operation. The class ConvolveOp provides a correlation from the source to the destination. The method filter(input, output) of class ConvolveOp performs a translation on BufferedImages.

The method write(output, "GIF", outputFile) writes into the output file logo.gif.

Here is the code of CopyImage.java

import java.io.*;
import java.awt.image.*;
import javax.imageio.ImageIO;

public class CopyImage {
    private static final float[] data = { 0.0f, -1.0f0.0f, -1.0f5.0f,
      -1.0f0.0f, -1.0f0.0f };
    public static void main(String args[]) throws IOException {
    File fileIn = new File("image4.jpg");
    BufferedImage bufferedImage1 = ImageIO.read(fileIn);
    Kernel kernel = new Kernel(33, data);
    ConvolveOp convolveOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP,
        null);
    int width = bufferedImage1.getWidth();
    int height = bufferedImage1.getHeight();
    BufferedImage bufferedImage2 = new BufferedImage(width, height,
        BufferedImage.TYPE_INT_ARGB);
    convolveOp.filter(bufferedImage1, bufferedImage2);
    File fileOut = new File("logo.gif");
    ImageIO.write(bufferedImage2, "GIF", fileOut);
  }
}

When you run the above program, the input file is copied into the output file specified.

Download Source Code

                         

» View all related tutorials
Related Tags: c class orm form io method sed format 2d get ip translation return instance transform show for transformation to draw

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 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

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 | Flex 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.