RGB颜色比对工具:http://tool.oschina.net/commons?type=3
RGB色彩模式分别分红绿蓝三种,它们的颜色取值范围是0~255,
其他的颜色则是通过这三个基本颜色合成。
颜色合成代码
int color=Color.rgb(red, green, blue)
场景:实现随机颜色
Random random = new Random();
int red = random.nextInt(255);
int green = random.nextInt(255);
int blue = random.nextInt(255);
int color=Color.rgb(red,green,blue);
将int 转化为 RGB
int color=-4253158;
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);
0xff0000的2进制是:111111110000000000000000(一共24位)
color & 0xff0000的意思:求和运算,得到一个000000000000000000000000-111111110000000000000000的数值, >>16的意思:右移16位,得到前8位的值,也就是00000000-11111111的数值,对应的2进制也就是0-255的值了。
green 和blue 同理。