Java Color Invert invertColor(int color)

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

Description

Invert the color

License

Open Source License

Parameter

Parameter Description
color a parameter

Return

inverted color

Declaration

public static int invertColor(int color) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//from  w  w  w . j  a  v a 2s  .  c  om
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/

public class Main {
    /**
     * Invert the color
     * 
     * @param color
     * @return inverted color
     */
    public static int invertColor(int color) {
        int a = (color >> 24) & 0xff;
        int r = (color >> 16) & 0xff;
        int g = (color >> 8) & 0xff;
        int b = color & 0xff;

        r = 255 - r;
        g = 255 - g;
        b = 255 - b;
        return toRGB(r, g, b, a);
    }

    /**
     * 
     * @param alpha
     * @param red
     * @param green
     * @param blue
     * @return
     */
    public static int toRGB(int alpha, int red, int green, int blue) {
        return (alpha & 0xff) << 24 | (red & 0xff) << 16 | (green & 0xff) << 8 | (blue & 0xff) << 0;
    }
}

Related

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