change Color Brightness - Android Graphics

Android examples for Graphics:Color Brighten

Description

change Color Brightness

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {
    /**// www. j  a  v  a 2s  .c om
     * @param color
     *            the color to change
     * @param amount
     *            the brigtnes offset (-255 to 255)
     * @return
     */
    public static int changeBrightness(final int color, final int amount) {
        final int a = Color.alpha(color);
        int r = Color.red(color);
        int g = Color.green(color);
        int b = Color.blue(color);

        r += amount;
        if (r > 255) {
            r = 255;
        }
        if (r < 0) {
            r = 0;
        }
        g += amount;
        if (g > 255) {
            g = 255;
        }
        if (g < 0) {
            g = 0;
        }
        b += amount;
        if (b > 255) {
            b = 255;
        }
        if (b < 0) {
            b = 0;
        }
        return Color.argb(a, r, g, b);
    }
}

Related Tutorials