[英]Change from ARGB Color to RRGGBB color
I want to set the values: Red: 0.910 green: 0.969 blue: 0.996 alpha: 1.0 我要设置值:红色:0.910绿色:0.969蓝色:0.996 alpha:1.0
I get color as: 我得到的颜色为:
int color=Color.argb(1.0,0.910,0.969,0.996)
but this doesn't work. 但这不起作用。
I want to get the value in hex color as #FF00FF. 我想以十六进制颜色获取值#FF00FF。 Any advice?
有什么建议吗?
Thanks 谢谢
Use this to get Hex values 使用此获取十六进制值
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;
}
eg : int color = toHex(new Color(1f, 1f, 1f, 1f)); 例如:int color = toHex(new Color(1f,1f,1f,1f));
Here's the link I refered to Convert RGBA values to hex color code 这是我引用的将RGBA值转换为十六进制颜色代码的链接
Related Links: 相关链接:
How to convert a color integer to a hex String in Android? 如何在Android中将颜色整数转换为十六进制字符串?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.