brighter Color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

brighter Color

Demo Code


//package com.java2s;

import java.awt.*;

public class Main {
    private static Color brighter(Color color, float FACTOR) {
        int r = color.getRed();
        int g = color.getGreen();
        int b = color.getBlue();
        int alpha = color.getAlpha();

        /* From 2D group:
         * 1. black.brighter() should return grey
         * 2. applying brighter to blue will always return blue, brighter
         * 3. non pure color (non zero rgb) will eventually return white
         *//*from  w  w w  .j a v  a2 s .c o  m*/
        int i = (int) (1.0 / (1.0 - FACTOR));
        if (r == 0 && g == 0 && b == 0) {
            return new Color(i, i, i, alpha);
        }
        if (r > 0 && r < i)
            r = i;
        if (g > 0 && g < i)
            g = i;
        if (b > 0 && b < i)
            b = i;

        return new Color(Math.min((int) (r / FACTOR), 255), Math.min(
                (int) (g / FACTOR), 255),
                Math.min((int) (b / FACTOR), 255), alpha);
    }
}

Related Tutorials