// 獲取更深顏色
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] 是色調(diào)(Hue),取值范圍是0到360摘符;hsv[1] 是飽和度( Saturation)紧显,取值范圍是0到1梢睛,值越高,顏色越接近光譜色伴箩;hsv[2] 是明度( Value )入愧,取值范圍是0到1。具體見百度百科HSV