Integer To Color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Integer To Color

Demo Code


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

public class Main {
    /**/*  www .j a va  2s . com*/
     * 
     * @param x
     * @return
     */
    public static Color IntegerToColor(int x) {
        int[] bytes = new int[4];

        bytes[0] = ((x & 0xff000000) >> 24);
        bytes[1] = ((x & 0xff0000) >> 16);

        if (bytes[1] < 0) {
            bytes[1] *= -1;
        }

        bytes[2] = ((x & 0xff00) >> 8);
        if (bytes[2] < 0) {
            bytes[2] *= -1;
        }

        bytes[3] = ((x & 0xff));

        if (bytes[3] < 0) {
            bytes[3] *= -1;
        }

        return new Color(bytes[3], bytes[2], bytes[1]);
    }
}

Related Tutorials