// 获取更深颜色
public static int getDarkerColor(int color){
float[] hsv = new float[3];
Color.colorToHSV(color, hsv); // convert to hsv
// make darker
hsv[1] = hsv[1] + 0.1f; // 饱和度更高
hsv[2] = hsv[2] - 0.1f; // 明度降低
int darkerColor = Color.HSVToColor(hsv);
return darkerColor ;
}
// 获取更浅的颜色
public int getBrighterColor(int color){
float[] hsv = new float[3];
Color.colorToHSV(color, hsv); // convert to hsv
hsv[1] = hsv[1] - 0.1f; // less saturation
hsv[2] = hsv[2] + 0.1f; // more brightness
int darkerColor = Color.HSVToColor(hsv);
return darkerColor ;
}
Color.colorToHSV
方法就是Convert the ARGB color to its HSV components.
HSV是一种颜色模型,hsv[0] 是色调(Hue),取值范围是0到360;hsv[1] 是饱和度( Saturation),取值范围是0到1,值越高,颜色越接近光谱色;hsv[2] 是明度( Value ),取值范围是0到1。具体见百度百科HSV