Here you can find the source of brightness(Color c, float scale)
Parameter | Description |
---|---|
c | The color to adjust |
scale | The factor (a value from -1 to 1) |
public static Color brightness(Color c, float scale)
//package com.java2s; /* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License./*from ww w .j a v a2s .com*/ */ import java.awt.Color; public class Main { /** * Adjusts the brightness of the given color. * @param c The color to adjust * @param scale The factor (a value from -1 to 1) */ public static Color brightness(Color c, float scale) { int r = c.getRed(); int g = c.getGreen(); int b = c.getBlue(); if (r == 0 && g == 0 && b == 0 && scale > 0) { r = g = b = Math.min(255, (int) (255 * scale)); } else { r = Math.max(0, (int) (r * scale)); g = Math.max(0, (int) (g * scale)); b = Math.max(0, (int) (b * scale)); if (r > 255 || g > 255 || b > 255) { return c; } } return new Color(r, g, b); } }