Java Color Invert invertColor(int color)

Here you can find the source of invertColor(int color)

Description

Inverts color parsed as integer

License

Open Source License

Parameter

Parameter Description
color a parameter

Return

inverted color as integer

Declaration

public static int invertColor(int color) 

Method Source Code

//package com.java2s;
/**/*w  w w.  ja  va  2 s .  co  m*/
 * Get a short description of the licensing terms.
 */

import java.awt.Color;

public class Main {
    /**
     * Inverts color parsed as integer
     * 
     * @param color 
     * @return inverted color as integer
     * @see java.awt.Color
     */
    public static int invertColor(int color) {
        Color origColor = new Color(color);

        /*
         * color's integer has format:
         * red: bits  16-23
         * green: bits 8-15
         * blue: bits 0-7
         * 
         * so we need to invert the individual components (R,G,B)
         * and put them to their decade
         */

        int invertedRed = ((255 - origColor.getRed()) * 65536);
        int invertedGreen = ((255 - origColor.getGreen()) * 256);
        int invertedBlue = ((255 - origColor.getBlue()));

        return invertedRed + invertedGreen + invertedBlue;
    }
}

Related

  1. invert(Color color)
  2. invert(Color color)
  3. invert(Color colour)
  4. invertColor(Color c)
  5. invertColor(Color cColor)
  6. invertColor(int color)
  7. invertColor(int color)