get Color RGB - Java 2D Graphics

Java examples for 2D Graphics:Color RGB

Description

get Color RGB

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        int rgb = 2;
        double brightness = 2.45678;
        System.out.println(getColorRGB(rgb, brightness));
    }/* w ww  . j  a  va  2 s  .c  om*/

    static int getColorRGB(int rgb, double brightness) {

        Color base = new Color(rgb);
        int red = Math
                .max(Math
                        .min(255,
                                (int) (base.getRed() + (base.getRed() * (1.5 * brightness)))),
                        0);
        int green = Math
                .max(Math
                        .min(255,
                                (int) (base.getGreen() + (base.getGreen() * (brightness)))),
                        0);
        int blue = Math.max(Math.min(255,
                (int) (base.getBlue() + (base.getBlue() * (brightness)))),
                0);
        return new Color(red, green, blue).getRGB();
    }
}

Related Tutorials