我有一个ARGB颜色(看起来像255 200 200 000
)。我尝试使用以下代码将其转换为十六进制格式:
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));
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句