2013-02-27 14 views

Odpowiedz

19
String.format("#%06x", color.getRGB() & 0x00FFFFFF) 

Maskowanie stosuje się do usuwania elementu alfa, w bitach 24-31

3
Color color = Color.BLUE; 
Formatter f = new Formatter(new StringBuffer("#")); 
f.format("%02X", color.getRed()); 
f.format("%02X", color.getGreen()); 
f.format("%02X", color.getBlue()); 
f.toString(); //#0000FF 
0

Istnieje inny sposób. Myślałem, że dodaję tę alternatywę.

// ARGB = (255, 255, 0, 0) (Red) 
// hex -> "ffff0000" 
String hex = Integer.toHexString(color.getRGB()); 

// Reduced to RGB: hex -> "#ff0000" 
hex = "#" + hex.substring(2, hex.length());