Darkens a color based on the float value entered. - Android Graphics

Android examples for Graphics:Color Darken

Description

Darkens a color based on the float value entered.

Demo Code

import android.graphics.Color;

public class Main {
  /**//from   w  w  w .j a va  2s . c  o m
   * Darkens a color based on the float value entered.
   * 
   * @param color
   *          your color int.
   * @param factor
   *          0.1 = 90% dark; 0.9 = 10% dark.
   * @return Color int.
   */
  public static int darkenColor(int color, float factor) {
    float[] hsv = new float[3];
    Color.colorToHSV(color, hsv);
    hsv[2] *= factor;
    return Color.HSVToColor(hsv);
  }
}

Related Tutorials