How to adjust the hue of the color code?

Can anyone know a way in Java (Android) to apply HUE to color code?

For example, if I have # 1589FF and apply 180 HUE, I should get # FF8B14.

+6
source share
2 answers

This should do the trick:

Color c = new Color(0x15, 0x89, 0xFF); // Get saturation and brightness. float[] hsbVals = new float[3]; Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsbVals); // Pass .5 (= 180 degrees) as HUE c = new Color(Color.HSBtoRGB(0.5f, hsbVals[1], hsbVals[2])); 
+10
source

Another attractive way to do this

  /** * @param color the ARGB color to convert. The alpha component is ignored * @param hueFactor The factor of hue, an int [0 .. 360) * @return new color with the specified hue. */ public int hue(int color, int hueFactor) { float[] hsl= new float[3]; ColorUtils.colorToHSL(color,hsl); hsl[0]=hueFactor; return ColorUtils.HSLToColor(hsl); } 
0
source

Source: https://habr.com/ru/post/897126/


All Articles