0xFFFF0000 color to rgba(255,255,0,0) conversion

0

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.

java
android
android-studio

1 Answer

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.

answered on Stack Overflow Oct 13, 2020 by Benjamin Cassidy

User contributions licensed under CC BY-SA 3.0