[英]Android - Convert ARGB Color to HEX
我有一個ARGB顏色(看起來像255 200 200 000
)。 我嘗試使用以下代碼將其轉換為Hex格式:
String col = "#" + Integer.toString(Color.alpha(img.getPixel(j, i)), 16) +
Integer.toString(Color.red(img.getPixel(j, i)), 16) +
Integer.toString(Color.green(img.getPixel(j, i)), 16) +
Integer.toString(Color.blue(img.getPixel(j, i)), 16);
但我得到了這個( #FFC8C8
)而不是( #FFC8C800
)。 所以低於10的所有數字都是沒有零的。 我如何修復該代碼以使其正常工作?
PS借口我的英語
您可以使用
String hexColor = String.format("#%08X", img.getPixel(j, i));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.