Java BufferedImage Operation revertBlackAndWhite(BufferedImage img)

Here you can find the source of revertBlackAndWhite(BufferedImage img)

Description

revert Black And White

License

Open Source License

Declaration

public static BufferedImage revertBlackAndWhite(BufferedImage img)
        throws Exception 

Method Source Code

//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;
    }
}

Related

  1. recombine(BufferedImage[][] blocks)
  2. reorientImage(BufferedImage image, boolean yAxisFlipNeeded, int cwRotationNeeded)
  3. repairImage(final BufferedImage bfi, final List order)
  4. resampleImage(BufferedImage image, int height)
  5. resampleWithAffineTransformOp(BufferedImage srcImage, double sx, double sy)
  6. roate90(BufferedImage src)
  7. sample9Points(BufferedImage src, int x, int y)
  8. scanFill(BufferedImage sourceImage)
  9. scrapeColors(BufferedImage image)