Read/Write Image using Java

We will see how we can read an image using Java. We know there are several kinds of image formats such as JPEG, GIF, PNG, BMP, TIFF etc. Java has built-in Image I/O API in javax.imageio package and it can be used to load external image formats into its BufferedImage formats. By default, Image I/O supports image formats such as JPEG, PNG, GIF, BMP, WBMP. It can also be extensible to support additional image formats for TIFF and JPEG 2000.

Image I/O recognises the contents of the file as a JPEG format image, and decodes it into a BufferedImage which can be directly used by Java 2D.

Image can be load or read using following code snippets, where imagePath is the full path with image name from where the image can be read.

 

Image can be write using the following code snippets, where bufferedImage is the BifferedImage read using ImageIO.read(); format is the output image format; file is the new File() object created using image full output path with image name.

 

You can save the below image for reading and writing.

read/write image using java

Now I will put whole source code for reading from and writing to an image file using Java. You can customize as per your requirements.

 

That’s all. Thank you for reading this article.

Soumitra

Software Professional, I am passionate to work on web/enterprise application. For more information please go to about me. You can follow on Twitter. You can be a friend on Facebook or Google Plus or Linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.