gpt4 book ai didi

java - 从 ARGB 颜色更改为 RRGGBB 颜色

转载 作者:行者123 更新时间:2023-11-30 03:32:50 25 4
gpt4 key购买 nike

我想设置值:红色:0.910 绿色:0.969 蓝色:0.996 alpha:1.0
我得到的颜色是:

int color=Color.argb(1.0,0.910,0.969,0.996)

但这行不通。

我想获取十六进制颜色的值 #FF00FF。有什么建议吗?

谢谢

最佳答案

使用它来获取十六进制值

protected int toHex(Color col) {
String as = pad(Integer.toHexString(col.getAlpha()));
String rs = pad(Integer.toHexString(col.getRed()));
String gs = pad(Integer.toHexString(col.getGreen()));
String bs = pad(Integer.toHexString(col.getBlue()));
String hex = "0x" + as + rs + gs + bs;
return Integer.parseInt(hex, 16);
}

private static final String pad(String s) {
return (s.length() == 1) ? "0" + s : s;
}

例如:int color = toHex(new Color(1f, 1f, 1f, 1f));

这是我提到的链接 Convert RGBA values to hex color code

相关链接:

How to convert a color integer to a hex String in Android?

关于java - 从 ARGB 颜色更改为 RRGGBB 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17160681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com