2013-12-15 101 views
2

我有一個ARGB顏色(看起來像255 200 200 000)。我試圖把它轉換成十六進制格式的代碼:Android - 將ARGB顏色轉換爲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); 

但我gettng這個(#FFC8C8),而不是(#FFC8C800)。所以低於10的所有數字都寫入零。 如何修復該代碼以使其正常工作?

P.S.藉口,我的英語

+0

哪些錯誤有: 「#」 + Integer.toString(img.getPixel(J,I)),16) – pskink

+0

它不返回一個0 – enCrypter

回答

2

您可以使用

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

完美的作品!非常感謝你!! – enCrypter