![](/img/trans.png)
[英]Color value not valid — must be #rgb, #argb, #rrggbb, or #aarrggbb
[英]Change from ARGB Color to RRGGBB color
我要設置值:紅色: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));
這是我引用的將RGBA值轉換為十六進制顏色代碼的鏈接
相關鏈接:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.