Returns the red channel of the color - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

Returns the red channel of the color

Demo Code

/**/*from  ww  w  . j av a2s.  c o  m*/
 * Utility class to deal with ARGB color format
 *
 * @author Aritz Lopez
 * @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
 */
//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int color = 2;
        System.out.println(getRed(color));
    }

    /**
     * The mask to get the two least significant bytes of an integer;
     */
    public static final int MASK = 0xFF;
    /**
     * The shifting used to put the red component in position
     */
    public static final int RED_SHIFT = 16;

    /**
     * Returns the red channel of the color
     *
     * @param color The color to get the red channel of
     * @return The red channel of the color
     */
    public static int getRed(final int color) {
        return (color >> RED_SHIFT) & MASK;
    }
}

Related Tutorials