java - 简单来说,Graphics.setXORMode(Color) 的作用是什么?

标签 java xor

这是我读到的有关它的内容,但无法准确理解它的作用:

One way to implement rubber-banding is to draw in XOR mode. You set XOR mode by calling the setXORMode() method for a graphics context and passing a color to it — usually the background color. In this mode the pixels are not written directly to the screen. The color in which you are drawing is combined with the color of the pixel currently displayed together with a third color that you specify, by exclusive ORing them together, and the resultant pixel color is written to the screen. The third color is usually set to be the background color, so the color of the pixel that is written is the result of the following operation:

resultant_Color = foreground_color^background_color^current_color

我知道异或运算的工作原理,但不知道上面的段落是什么意思。请帮我解释一下

最佳答案

它接受颜色并应用 XOR 掩码,就像常规 XOR 会位掩码一样,但它是在 RGB 颜色上,因此如果它覆盖具有相同值或相同值的颜色,它会生成您传入的颜色。如果值不同,则为该颜色 RGB 的反转,以及低于其 RGB 的颜色。

只需编写一些代码并尝试一下,就会立即看出会发生什么。

关于java - 简单来说,Graphics.setXORMode(Color) 的作用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12127187/

相关文章:

java - JPA加载实体,但在@OneToMany列表中,仅加载特定的

Java+CPLEX LazyConstraintCallback 未知对象异常

java - jdbc的Mysql语法异常

java - Hamcrest allOf() 的签名是错误的吗?

c++ - 带有插入符号操作的字符 XOR

python - 如何仅对列表中的指定位进行异或

javascript - Javascript 中的 XOR 运算符用于检查值

java - 在同一页中打印两个 JPanel

python - pybrain 结果不佳

c# - 我怎样才能最好地检查 A xor B 是否为空?