to Normalized RGBA - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

to Normalized RGBA

Demo Code


//package com.java2s;

public class Main {
    public static float[] toNormalizedRGBA(int color) {
        int[] rgba = toRGBA(color);

        return new float[] { rgba[0] / 255f, rgba[1] / 255f,
                rgba[2] / 255f, rgba[3] / 255f };
    }/*from  www.  ja v  a  2 s  .c o m*/

    public static int[] toRGBA(int color) {
        int alpha = color >> 24 & 255;
        int red = color >> 16 & 255;
        int green = color >> 8 & 255;
        int blue = color & 255;

        return new int[] { red, green, blue, alpha };
    }
}

Related Tutorials