简体   繁体   English

设置Java java.awt.Color RGB组件的LSB

[英]Set the LSB of Java java.awt.Color RGB components

有没有一种方法可以更改java.awt.Color RGB组件的LSB值?

The Color class is immutable, you can't change anything. Color类是不可变的,您不能更改任何内容。 However, you can create a new color with whatever value you want. 但是,您可以使用任意值创建新颜色。 For example, 例如,

   int oldValue = oldColor.getRGB();
   int newValue = (oldValue & 0xFFFFFF00) | (lsb & 0xFF);
   Color newColor = new Color(newValue);

Turning a bit on: 打开一点:

int value = someValue | 0x1;

Turning a bit off: 关闭一点:

int value = someValue & (~0x1);

Toggling the bit on or off if it was off or on before: 如果位是关闭或之前打开或关闭,请执行以下操作:

int value = someValue ^ 0x1;

In other words: someValue is binary OR'ed with a number with the LSB on so the resulting number will have its LSB on too. 换句话说:someValue是二进制的,并且将数字与LSB一起打开,因此所得数字也将具有其LSB。

someValue is AND'ed with a number with all bits except LSB on so the resulting number will have LSB OFF. someValue与一个数字进行了“与”运算, LSB 以外的所有位都为 ON,因此所得数字的LSB为OFF。

someValue is XOR'ed with with a number with the LSB on, so the resulting number will have its LSB toggled. 在LSB启用的情况下,将someValue与数字进行异或运算,因此将转换得到的数字的LSB。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM