//rgb颜色转16进制
1 public String convertRGBToHex(Color color) { 2 String rFString, rSString, gFString, gSString, 3 bFString, bSString, result; 4 int r = color.getRed(); 5 int g = color.getGreen(); 6 int b = color.getBlue(); 7 int red, green, blue; 8 int rred, rgreen, rblue; 9 red = r / 16; 10 rred = r % 16; 11 if (red == 10) rFString = "A"; 12 else if (red == 11) rFString = "B"; 13 else if (red == 12) rFString = "C"; 14 else if (red == 13) rFString = "D"; 15 else if (red == 14) rFString = "E"; 16 else if (red == 15) rFString = "F"; 17 else rFString = String.valueOf(red); 18 19 if (rred == 10) rSString = "A"; 20 else if (rred == 11) rSString = "B"; 21 else if (rred == 12) rSString = "C"; 22 else if (rred == 13) rSString = "D"; 23 else if (rred == 14) rSString = "E"; 24 else if (rred == 15) rSString = "F"; 25 else rSString = String.valueOf(rred); 26 27 rFString = rFString + rSString; 28 29 green = g / 16; 30 rgreen = g % 16; 31 32 if (green == 10) gFString = "A"; 33 else if (green == 11) gFString = "B"; 34 else if (green == 12) gFString = "C"; 35 else if (green == 13) gFString = "D"; 36 else if (green == 14) gFString = "E"; 37 else if (green == 15) gFString = "F"; 38 else gFString = String.valueOf(green); 39 40 if (rgreen == 10) gSString = "A"; 41 else if (rgreen == 11) gSString = "B"; 42 else if (rgreen == 12) gSString = "C"; 43 else if (rgreen == 13) gSString = "D"; 44 else if (rgreen == 14) gSString = "E"; 45 else if (rgreen == 15) gSString = "F"; 46 else gSString = String.valueOf(rgreen); 47 48 gFString = gFString + gSString; 49 50 blue = b / 16; 51 rblue = b % 16; 52 53 if (blue == 10) bFString = "A"; 54 else if (blue == 11) bFString = "B"; 55 else if (blue == 12) bFString = "C"; 56 else if (blue == 13) bFString = "D"; 57 else if (blue == 14) bFString = "E"; 58 else if (blue == 15) bFString = "F"; 59 else bFString = String.valueOf(blue); 60 61 if (rblue == 10) bSString = "A"; 62 else if (rblue == 11) bSString = "B"; 63 else if (rblue == 12) bSString = "C"; 64 else if (rblue == 13) bSString = "D"; 65 else if (rblue == 14) bSString = "E"; 66 else if (rblue == 15) bSString = "F"; 67 else bSString = String.valueOf(rblue); 68 bFString = bFString + bSString; 69 result = "#" + rFString + gFString + bFString; 70 return result; 71 }