Java BufferedImage Invert invertImage(BufferedImage image)

Here you can find the source of invertImage(BufferedImage image)

Description

Perform image invert operation.

License

Open Source License

Parameter

Parameter Description
image Input Image

Return

Inverted image

Declaration


public static void invertImage(BufferedImage image) 

Method Source Code

//package com.java2s;
/**/*from  w  w  w  .  j  av  a2  s  .c o  m*/
 * Copyright 2014 Comcast Cable Communications Management, LLC
 *
 * This file is part of CATS.
 *
 * CATS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * CATS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with CATS.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.image.BufferedImage;

public class Main {
    /**
     * Perform image invert operation.
     * 
     * @param image
     *            Input Image
     * @return Inverted image
     */

    public static void invertImage(BufferedImage image) {
        int width = image.getWidth();
        int height = image.getHeight();
        int new_rgb;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                new_rgb = (~(image.getRGB(x, y)));
                image.setRGB(x, y, new_rgb);
            }

        }

    }
}

Related

  1. invert(BufferedImage inImg)
  2. invertImage(BufferedImage image)
  3. invertImage(BufferedImage img, boolean newImage)
  4. invertImage(final BufferedImage savedImage)