Here you can find the source of binary(BufferedImage src)
public static final BufferedImage binary(BufferedImage src)
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class Main { public static final BufferedImage binary(BufferedImage src) { int width = src.getWidth(); int height = src.getHeight(); BufferedImage grayImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY); for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { int rgb = src.getRGB(i, j); grayImage.setRGB(i, j, rgb); }/*www. ja va2 s . co m*/ } return grayImage; } public static final BufferedImage binary(File f) throws IOException { BufferedImage src = ImageIO.read(f); return binary(src); } }