Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to adjust the hue of a color code?

Tags:

java

android

Maybe someone know of a way in Java (Android) to apply HUE to a color code?

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

like image 531
Roger Avatar asked Sep 12 '11 06:09

Roger


1 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]));
like image 60
aioobe Avatar answered Sep 28 '22 09:09

aioobe