What does Graphics.setXORMode(Color) do in simple terms?

旧时模样 提交于 2019-12-17 21:33:05

问题


Here is what I read about it but cant understand exactly what it does:

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

I know how XORing works but don't know what the above paragraph means. Please elucidate it for me


回答1:


It takes a color in and applies an XOR mask just like a regular XOR would a bit mask, except it is on the RGB colors, so it produces the color you pass in if it overlays a color with the same values or the inverse of that colors RGB and and color below its RGB if the values are different.

Just write some code and try it and it will be immediate evident what happens.



来源:https://stackoverflow.com/questions/12127187/what-does-graphics-setxormodecolor-do-in-simple-terms

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!