需求
代码
float[] outHsl = new float[]{0f, 0f, 0f};
ColorUtils.colorToHSL(Color.parseColor("#ef2b2c"), outHsl);
((ImageView) findViewById(R.id.imageView5)).setBackgroundColor(Color.parseColor("#ef2b2c"));
LogUtils.e("" + outHsl.toString());
float[] newHsl = new float[]{15, outHsl[1] * 1.16f, outHsl[2] * 0.93f};
ColorUtils.HSLToColor(newHsl);
((ImageView) findViewById(R.id.imageView6)).setBackgroundColor(ColorUtils.HSLToColor(newHsl));
((ImageView) findViewById(R.id.imageView7)).setBackgroundColor(Color.parseColor("#ff4306"));
float[] outHsl1 = new float[]{0f, 0f, 0f};
ColorUtils.colorToHSL(Color.parseColor("#ff4306"), outHsl1);
((TextView) findViewById(R.id.textView10)).setText("主 #ef2b2c \n" +
"SHL" + Arrays.toString(outHsl) + "\n" +
"C1 #ff4306 \n" +
"C1 SHL" + Arrays.toString(newHsl) + "\n" +
"C1 SHL" + Arrays.toString(outHsl1) + "\n"
);
结果
简单的封装使用
/**
*
* @param color 颜色值
* @param outHsl 输出比例
* @return
*/
public static int computeHSL(String color, float... outHsl) {
float[] hsl = new float[]{0f, 0f, 0f};
ColorUtils.colorToHSL(Color.parseColor(color), hsl);
float[] newHsl = new float[]{outHsl[0], hsl[1] * outHsl[1], hsl[2] * outHsl[2]};
return ColorUtils.HSLToColor(newHsl);
}