Java Color Brighten brighter(Color color)

Here you can find the source of brighter(Color color)

Description

Lighten up a color.

License

Open Source License

Parameter

Parameter Description
color The color to lighten up.

Return

A new, brighter variant of the Color passed in the 'color' parameter.

Declaration

public static Color brighter(Color color) 

Method Source Code


//package com.java2s;
/*//from   w w  w .  j  av  a 2 s.  co m
 * This class contains various graphics and color utility methods.
 *
 * Copyright (C) 1999 Thomas Studer
 * mailto:tstuder@datacomm.ch
 * http://www.datacomm.ch/tstuder
 *
 * This class is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This class is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this class; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

import java.awt.Color;

public class Main {
    private static final Color WHITE_BRIGHTER = new Color(200, 200, 200);
    private static final Color BLACK_BRIGHTER = new Color(125, 125, 125);
    private static final double FACTOR = 0.5;

    /**
     * Lighten up a color.
     *
     * @return A new, brighter variant of the Color passed in the 'color' parameter.
     * @param color The color to lighten up.
     */
    public static Color brighter(Color color) {

        if (color.equals(Color.white))
            return WHITE_BRIGHTER;
        else if (color.equals(Color.black))
            return BLACK_BRIGHTER;
        else {
            // Brighten up dark colors very
            // quickly; lighten up bright colors only a bit.
            int red = color.getRed();
            red += (int) ((255 - red) * FACTOR);
            int blue = color.getBlue();
            blue += (int) ((255 - blue) * FACTOR);
            int green = color.getGreen();
            green += (int) ((255 - green) * FACTOR);

            return new Color(Math.min(red, 255), Math.min(green, 255), Math.min(blue, 255));
        }
    }
}

Related

  1. brighter(Color c)
  2. brighter(Color c, double factor)
  3. brighter(Color c, double p)
  4. brighter(Color col, double FACTOR)
  5. brighter(Color color)
  6. brighter(Color color, double factor)
  7. brighter(Color color, float factor)
  8. brighterColor(Color c)
  9. brighterColor(String hexValue)