java模拟颜色通道的的提取

刚写的demo,各位可参考参考

public class ColorHexPrint {
    public static void main(String[] args) {
        //java int类型刚好32位,刚好可以用来测试颜色的操作
         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));
    
    //从灰色里面取出红色通道  删除透明通道 , 绿色通道 蓝色通道 , 也就是取出 第一个cc
    int and=colorGray&0x00ff0000;
    //取出来之后这个值是很变态的, ox cc 00  00; 这一步 蓝色和绿色通道被清空了,但是还需要再继续,
    System.out.println("第一步:"+Integer.toHexString(and));
    int fixand=and>>(int) Math.pow(4, 4);
//       int fixand=and>>16;//移动多少个比特位,  1个字节有4个bit位  一个颜色 2个字节 这里 要取出红色通道,所以蓝色和绿色 的话就又4个字节,4的4平方
    System.out.println("第二步:"+Integer.toHexString(fixand)+","+( Math.pow(4, 2)));

    }
}
image.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值