剛寫的demo,各位可參考參考
public class ColorHexPrint {
public static void main(String[] args) {
//java int類型剛好32位旬盯,剛好可以用來測(cè)試顏色的操作
int color = 0xffef2f;
int colorGray=0xffcccccc;
int colorFull=0xffffef2f;
int colorRed=(255*2)<<16;
int fullWhite=0xffffffff;
int fullWhite1=0b1111_1111_1111_1111______1111_1111_1111_1111;
System.out.println("ox"+Integer.toHexString(color)+",color:"+Integer.toHexString(colorFull)+",RED:"
+Integer.toHexString(colorRed)+",white:"+Integer.toHexString(fullWhite)+",fullWhite1:"+Integer.toHexString(fullWhite1));
//從灰色里面取出紅色通道 刪除透明通道 盈电, 綠色通道 藍(lán)色通道 遣铝, 也就是取出 第一個(gè)cc
int and=colorGray&0x00ff0000;
//取出來之后這個(gè)值是很變態(tài)的, ox cc 00 00; 這一步 藍(lán)色和綠色通道被清空了球切,但是還需要再繼續(xù)疯潭,
System.out.println("第一步:"+Integer.toHexString(and));
int fixand=and>>(int) Math.pow(4, 4);
// int fixand=and>>16;//移動(dòng)多少個(gè)比特位嘱根, 1個(gè)字節(jié)有4個(gè)bit位 一個(gè)顏色 2個(gè)字節(jié) 這里 要取出紅色通道嚣潜,所以藍(lán)色和綠色 的話就又4個(gè)字節(jié),4的4平方
System.out.println("第二步:"+Integer.toHexString(fixand)+","+( Math.pow(4, 2)));
}
}
image.png