移位运算RGB

来源:互联网 发布:易观大数据峰会 编辑:程序博客网 时间:2024/06/05 16:02
package com.xiuye.homework;public class demo26 {public static void main(String[] args) {int r = 255;int g = 99;int b = 49;outRGB(r,g,b);System.out.println("===========================");r = 0xff;g = 0xff;b = 0xff;outRGB(r,g,b);System.out.println("===========================");r = 0x01;g = 0x01;b = 0x01;outRGB(r,g,b);System.out.println("========================");outRGBOptimization(r,g,b);}public static void outRGB(int r,int g,int b){/** * 0x00 ff  ff ff *  alpha red  green blue */r &= 0xff;g &= 0xff;b &= 0xff;int rgb = (r<<16)+(g<<8)+b;System.out.println(rgb);System.out.println(Integer.toBinaryString(rgb));}public static void outRGBOptimization(int r,int g,int b){/** * 0x00 ff  ff ff *  alpha red  green blue */r &= 0xff;g &= 0xff;b &= 0xff;int rgb = (r<<16)|(g<<8)|b;System.out.println(rgb);System.out.println(Integer.toBinaryString(rgb));}}


0 0
原创粉丝点击