Creates a color that corresponds to the specified values. - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Creates a color that corresponds to the specified values.

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        int red = 2;
        int green = 2;
        int blue = 2;
        System.out.println(create(red, green, blue));
    }//ww w . jav a  2 s  . c  o  m

    /**
     * Creates a color that corresponds to the specified values.
     *
     * @param red is an integer between 0 and 255
     * @param green is an integer between 0 and 255
     * @param blue is an integer between 0 and 255
     */
    public static int create(int red, int green, int blue) {
        int value = (red & 0xff);
        value |= (green & 0xff) << 8;
        value |= (blue & 0xff) << 16;
        return value;
    }
}

Related Tutorials