get RGBA Color - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

get RGBA Color

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int tag = 2;
        float A = 2.45678f;
        System.out.println(java.util.Arrays.toString(getRGBAColor(tag, A)));
    }//from w  w w.  j a  v a  2  s .c om

    public static void getRGBAColor(int tag, float A, float[] res) {
        res[3] = A;
        for (int i = 0; i < 3; i++) {
            res[2 - i] = tag & 0xff;
            res[2 - i] = res[2 - i] / 0xff;
            tag = tag >> 8;
        }
    }

    public static float[] getRGBAColor(int tag, float A) {
        float[] color = new float[4];
        color[3] = A;
        for (int i = 0; i < 3; i++) {
            color[2 - i] = tag & 0xff;
            color[2 - i] = color[2 - i] / 0xff;
            tag = tag >> 8;
        }
        return color;
    }

    public static float[] getRGBAColor(float R, float G, float B, float A) {
        float[] color = new float[] { R, G, B, A };
        return color;
    }
}

Related Tutorials