Here you can find the source of revertBlackAndWhite(BufferedImage img)
public static BufferedImage revertBlackAndWhite(BufferedImage img) throws Exception
//package com.java2s; import java.awt.Color; import java.awt.image.BufferedImage; public class Main { public static BufferedImage revertBlackAndWhite(BufferedImage img) throws Exception { int width = img.getWidth(); int height = img.getHeight(); for (int x = 0; x < width; ++x) { for (int y = 0; y < height; ++y) { if (isWhite(img.getRGB(x, y)) == 1) { img.setRGB(x, y, Color.BLACK.getRGB()); } else { img.setRGB(x, y, Color.WHITE.getRGB()); }/* w w w . j a v a 2 s . c om*/ } } return img; } public static int isWhite(int colorInt) { Color color = new Color(colorInt); if (color.getRed() + color.getGreen() + color.getBlue() > 500) { return 1; } return 0; } }