"" 24- RGB: 1 (8 ) , , . 0-255 0x00 0xff .
- : #FFFFFF, - : # 000000. , , .
, :
if (red + green + blue <= (0xff * 3) / 2)
fontcolor = white;
else
fontcolor = black;
: asker , , :
public static void main(String[] args) throws IOException {
String value =
"#112233";
int red = Integer.parseInt(value.substring(1, 1 + 2), 16);
int green = Integer.parseInt(value.substring(3, 3 + 2), 16);
int blue = Integer.parseInt(value.substring(5, 5 + 2), 16);
System.out.println("red = " + Integer.toHexString(red)
+ ", green = " + Integer.toHexString(green)
+ ", blue = " + Integer.toHexString(blue));
if (red + green + blue <= 0xff * 3 / 2)
System.out.println("using white color #ffffff");
else
System.out.println("using black color #000000");
String colorBackToString = "#" + Integer.toHexString(red) +
Integer.toHexString(green) +
Integer.toHexString(blue);
System.out.println("color was " + colorBackToString);
}
:
red = 11, green = 22, blue = 33
using white color #ffffff
color was #112233
#aabbcc rgb, ( ) ..