tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Image IO > How to create Black and White image from color image

How to create Black and White image from color image 

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 converting colored image to black and white image.


File Name  :  
Author  :  Sudhakar KV
Email  :  [email protected]
package com.bethecoder.tutorials.imageio;

import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;

public class BlackAndWhiteTest {

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

    File file = new File("C:/Temp/stpatricks_08.gif");
    BufferedImage orginalImage =;

    BufferedImage blackAndWhiteImg = new BufferedImage(
        orginalImage.getWidth(), orginalImage.getHeight(),
    Graphics2D graphics = blackAndWhiteImg.createGraphics();
    graphics.drawImage(orginalImage, 00null);

    ImageIO.write(blackAndWhiteImg, "png"new File("c:/Temp/stpatricks_08_bw.png"))


It gives the following output,


bl  br