Get Color from hex - Java 2D Graphics

Java examples for 2D Graphics:Color HEX

Description

Get Color from hex

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        int parHex = 2;
        System.out.println(getColor(parHex));
    }//  w w  w  .j  av  a2s.c o m

    /**Get Color from hex*/
    public static Color getColor(int parHex) {
        return new Color(getRed(parHex), getGreen(parHex), getBlue(parHex));
    }

    /**Get red from hex*/
    public static int getRed(int parHex) {
        return (parHex >> 16) & 0xFF;
    }

    /**Get green from hex*/
    public static int getGreen(int parHex) {
        return (parHex >> 8) & 0xFF;
    }

    /**Get blue from hex*/
    public static int getBlue(int parHex) {
        return parHex & 0xFF;
    }
}

Related Tutorials