A simpler solution using HSV, such as RogueBaneling, offers:
Kotlin
@ColorInt fun darkenColor(@ColorInt color: Int): Int { return Color.HSVToColor(FloatArray(3).apply { Color.colorToHSV(color, this) this[2] *= 0.8f }) }
Java
@ColorInt int darkenColor(@ColorInt int color) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); hsv[2] *= 0.8f; return Color.HSVToColor(hsv); }
No complex bitwise operations or Math operations are required. Move 0.8f to the argument, if necessary.
source share