Android - 将ARGB颜色转换为HEX

时间:2013-12-15 16:53:55

标签: java android colors

我有一个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的所有数字都是没有零的。 我如何修复该代码以使其正常工作?

P.S。我的英语借口

1 个答案:

答案 0 :(得分:2)

您可以使用

String hexColor = String.format("#%08X", img.getPixel(j, i));
相关问题