Get the RGB colors from a RGB color value and store into an array (ignores alpha) - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

Get the RGB colors from a RGB color value and store into an array (ignores alpha)

Demo Code

//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int rgb = 2;
        System.out.println(java.util.Arrays.toString(getColorArray(rgb)));
    }//from   w  w w  . j  av a 2s  . c om

    /**
     * Get the RGB colors from a RGB color value and store into an array (ignores alpha)
     * 
     * @param rgb
     * @return
     */
    public static int[] getColorArray(int rgb) {
        int[] c = new int[3];
        c[0] = rgb >> 16;
        c[1] = (rgb >> 8) & 255;
        c[2] = rgb & 255;
        return c;
    }
}

Related Tutorials