public static int RGB(float[] hsv) {
return Color.HSVToColor(hsv);
}
this function add an int, froma color. how can i convert that int to a hexa string: #efefef
public static int RGB(float[] hsv) {
return Color.HSVToColor(hsv);
}
this function add an int, froma color. how can i convert that int to a hexa string: #efefef
The answer of st0le is not correct with respect to colors. It does not work if first color components are 0. So toHexString is useless.
However this code will work as expected:
String strColor = String.format("#%06X", 0xFFFFFF & intColor);
Here are 2 ways to convert Integer to Hex Strings...
int n = 123456;
System.out.println(String.format("#%X", n)); //use lower case x for lowercase hex
System.out.println("#"+Integer.toHexString(n));
If you want to convert to javascript format:
val hexColor = String.format("%06X", 0xFFFFFFFF.and(R.color.text.toColorInt(context).toLong()))
val javascriptHexColor = "#" + hexColor.substring(2) + hexColor.substring(0, 2)
Use this way
Java:
String hexColor = "#" + Integer.toHexString(ContextCompat.getColor(context, R.color.colorTest))
Kotlin:
var hexColor = "#${Integer.toHexString(ContextCompat.getColor(context, R.color.colorTest))}"