Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 移动整数以获得ARGB灰度_Java_Colors - Fatal编程技术网

Java 移动整数以获得ARGB灰度

Java 移动整数以获得ARGB灰度,java,colors,Java,Colors,假设我有: int x = 140; 我想得到以下结果: int y = new Color(x, x, x).getRGB() 来自Java API文档: getRGB() 获取表示默认RGB ColorModel中颜色的RGB值。 (位24-31为0xff,16-23为红色,8-15为绿色,0-7为蓝色) 但我不确定换档是如何工作的,对吗 int y = 0xff + x<<16 + x<<8 + x; int y=0xff+x如果您没有忘记正确移动alpha

假设我有:

int x = 140;
我想得到以下结果:

int y = new Color(x, x, x).getRGB()
来自Java API文档:

getRGB()
获取表示默认RGB ColorModel中颜色的RGB值。
(位24-31为0xff,16-23为红色,8-15为绿色,0-7为蓝色)

但我不确定换档是如何工作的,对吗

 int y = 0xff + x<<16 + x<<8 + x;

int y=0xff+x如果您没有忘记正确移动alpha值,那么您的方法将有效

int y = (0xff<<24) + (x<<16) + (x<<8) + x;

int y=(0xFFThank!你能解释一下为什么我需要按位还是请?:)用0x008c0000添加0xff000000而不使用按位还是不给我0xff8c0000?@XandruDavid我很抱歉你是对的,但是你需要正确地移动alpha值。
int y = (0xff<<24) | (x<<16) | (x<<8) | x;
(0xff << 24) =>  0xff000000
| (x<<16)    =>  0xff8c0000
| (x<<8)     =>  0xff8c8c00
| x          =>  0xff8c8c8c