0xFFFF0000 颜色转换为 rgba(255,255,0,0)

huangapple go评论84阅读模式
英文:

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

问题

我使用duanhong169开发的Android颜色选择器。颜色以这种格式给出:0xFFFF0000,我想要将其转换为十进制的rgba格式,如255、255、0、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.

答案1

得分: 0

你可以使用Android SDK提供的Color类。

你想要做的关键是:

val color = Color.valueOf(0xFFFF0000)
color.red() * 256
color.green() * 256
color.blue() * 256
color.alpha() * 256

你需要乘以256,因为这些函数返回介于0和1之间的浮点值。

英文:

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.

huangapple
  • 本文由 发表于 2020年10月13日 23:14:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64338019.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定