Here you can find the source of invertImage(BufferedImage img, boolean newImage)
Parameter | Description |
---|---|
img | The image to invert |
newImage | Whether to return a new image or invert the given image. |
static public BufferedImage invertImage(BufferedImage img, boolean newImage)
//package com.java2s; import java.awt.image.BufferedImage; public class Main { /**// w ww .j a va2 s. c o m * Inverts the given image. * @param img The image to invert * @param newImage Whether to return a new image or invert the given image. * @return the inverted image */ static public BufferedImage invertImage(BufferedImage img, boolean newImage) { BufferedImage returnImage = img; if (newImage) returnImage = new BufferedImage(img.getWidth(), img.getHeight(), img.getType()); for (int y = 0; y < img.getHeight(); y++) { for (int x = 0; x < img.getWidth(); x++) { int in = img.getRGB(x, y); returnImage.setRGB(x, y, (in & 0xff000000) | ((~in) & 0x00ffffff)); } } return returnImage; } }