How can I generate the opposite color according to current color?

前端 未结 11 637
北海茫月
北海茫月 2020-11-28 01:53

I\'m trying to create a color opposite of current color. I mean if current color is black, then I need to generate white.

Actually I have a text

11条回答
  •  無奈伤痛
    2020-11-28 02:45

    In my understanding of your question, by opposite color you mean inverted color.

    InvertedColorComponent = 0xFF - ColorComponent
    

    So for the color red (#FF0000) this means: R = 0xFF or 255 G = 0x00 or 0 B = 0x00 or 0

    inverted color red (#00FFFF) is:

    R = 0xFF - 0xFF = 0x00 or 255 - 255 = 0
    G = 0xFF - 0x00 = 0xFF or 255 - 0 = 255
    B = 0xFF - 0x00 = 0xFF or 255 - 0 = 255
    

    Another examples:

    Black (#000000) becomes White (#FFFFFF).

    Orange (#FFA500) becomes #005AFF

提交回复
热议问题