简体   繁体   English

Android - 将ARGB颜色转换为HEX

[英]Android - Convert ARGB Color to HEX

I have an ARGB Color (looks like 255 200 200 000 ). 我有一个ARGB颜色(看起来像255 200 200 000 )。 I've tried to convert it into Hex format with this code: 我尝试使用以下代码将其转换为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);

But I'm gettng this ( #FFC8C8 ) instead of ( #FFC8C800 ). 但我得到了这个( #FFC8C8 )而不是( #FFC8C800 )。 So all numbers below 10 are writing without zeros. 所以低于10的所有数字都是没有零的。 How I can fix that code to make it work properly? 我如何修复该代码以使其正常工作?

PS Excuse for my English PS借口我的英语

您可以使用

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM