I use Android color picker by duanhong169. Color is given in this format: 0xFFFF0000 and i want to convert it to rgba format in decimal like 255, 255, 0, 0 I try to convert this to String then split it but the conversion output is decimal from all the hex number. I need decimal from every section.
Asked
Active
Viewed 740 times
0
-
Convert it to a long and do bit manipulations – Thorbjørn Ravn Andersen Oct 13 '20 at 15:17
-
1Does this answer your question? [Convert hex color value ( #ffffff ) to integer value](https://stackoverflow.com/questions/6935057/convert-hex-color-value-ffffff-to-integer-value) – Style-7 Oct 13 '20 at 15:26
1 Answers
0
You can use the Color class provided by the Android SDK.
Essential what you want to do is this:
val color = Color.valueOf(0xFFFF0000)
color.red() * 256
color.green() * 256
color.blue() * 256
color.alpha() * 256
You need to multiply by 256 because those functions return a float value between 0 and 1.

Benjamin Cassidy
- 827
- 1
- 8
- 23