I want to convert ARGB colors to CSS-compatible hex
for example:
-1
should be converted to #FFFFFF
or
-16777216
to #000000
How can I do that in JavaScript?
This discards any alpha component
function argbToRGB(color) {
return '#'+ ('000000' + (color & 0xFFFFFF).toString(16)).slice(-6);
}
Your colors are signed 32-bits and full alpha (0xFF) makes the numbers negative. This code works even for unsigned numbers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With