Java examples for 2D Graphics:Color RGB
Inverts a color (for each i in RGB, changes i to 255-i).
//package com.java2s; import java.awt.*; public class Main { /**//from ww w . ja v a 2s .c o m * Inverts a color (for each i in RGB, changes i to 255-i). Keeps alpha the * same. * * @param color * the color to invert. * @return the inverted color. */ public static Color invert(Color color) { int r = 255 - color.getRed(); int g = 255 - color.getGreen(); int b = 255 - color.getBlue(); return new Color(r, g, b, color.getAlpha()); } }