Get the color from a ARGB color value - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

Get the color from a ARGB color value

Demo Code


//package com.java2s;
import java.awt.Color;

public class Main {
    public static void main(String[] argv) throws Exception {
        int argb = 2;
        System.out.println(getColor(argb));
    }/*from  ww w.  j  av  a  2s.c om*/

    /**
     * Get the color from a ARGB color value
     * 
     * @param rgb
     * @return
     */
    public static Color getColor(int argb) {
        int a = (argb >> 24) & 255;
        int r = argb >> 16;
        int g = (argb >> 8) & 255;
        int b = argb & 255;
        return new Color(r, g, b, a);
    }
}

Related Tutorials