Home All Groups Group Topic Archive Search About
Author
26 Jul 2006 7:26 PM
Smokey Grindle
How can you "inverse" a color in GDI+? Say the color I have is blue, the
inverse of that is yellow... how would you go about doing this? is there a
simpler way then taking the RGB values and takeing the difference from 255?

Say blue is 0,0,255
the inverse would be 255,255,0 which is yellow, is masking this the only way
to go?

    0      0      255
- 255   255  255
==============
-255  -255   0

ABS(result) = 255,255,0

? or am i going the wrong way with this and there is an easier way. thanks!

Author
26 Jul 2006 7:57 PM
tommaso.gastaldi
hi Smokey

        Dim OriginalColor As Color = Color.RoyalBlue
        Dim InverseColor As Color = Color.FromArgb(Not OriginalColor.R,
Not OriginalColor.G, Not OriginalColor.B)

-t

Smokey Grindle ha scritto:

Show quoteHide quote
> How can you "inverse" a color in GDI+? Say the color I have is blue, the
> inverse of that is yellow... how would you go about doing this? is there a
> simpler way then taking the RGB values and takeing the difference from 255?
>
> Say blue is 0,0,255
> the inverse would be 255,255,0 which is yellow, is masking this the only way
> to go?
>
>     0      0      255
> - 255   255  255
> ==============
> -255  -255   0
>
> ABS(result) = 255,255,0
>
> ? or am i going the wrong way with this and there is an easier way. thanks!
Author
27 Jul 2006 11:01 AM
Göran_Andersson
Switch the operators in the subtraction, and you don't get a negative value:

255 - r, 255 - g, 255 - b

You can also use exclusive or:

r xor 255, g xor 255, b xor 255


Smokey Grindle wrote:
Show quoteHide quote
> How can you "inverse" a color in GDI+? Say the color I have is blue, the
> inverse of that is yellow... how would you go about doing this? is there a
> simpler way then taking the RGB values and takeing the difference from 255?
>
> Say blue is 0,0,255
> the inverse would be 255,255,0 which is yellow, is masking this the only way
> to go?
>
>     0      0      255
> - 255   255  255
> ==============
> -255  -255   0
>
> ABS(result) = 255,255,0
>
> ? or am i going the wrong way with this and there is an easier way. thanks!
>
>
Author
27 Jul 2006 3:38 PM
Larry Lard
Smokey Grindle wrote:
> How can you "inverse" a color in GDI+? Say the color I have is blue, the
> inverse of that is yellow... how would you go about doing this? is there a
> simpler way then taking the RGB values and takeing the difference from 255?
>
> Say blue is 0,0,255
> the inverse would be 255,255,0 which is yellow, is masking this the only way
> to go?

Not sure, but be aware that by this rule the inverse of medium gray
(808080) is... another medium gray (7f7f7f)

>
>     0      0      255
> - 255   255  255
> ==============
> -255  -255   0

Subtract the other way round.

>
> ABS(result) = 255,255,0
>
> ? or am i going the wrong way with this and there is an easier way. thanks!

If there were such a method it would be in Color, I imagine, and there
isn't one there. You might find a recent thread we had here about RGB -
HSL conversion interesting.

--
Larry Lard
larryl***@googlemail.com
The address is real, but unread - please reply to the group
For VB and C# questions - tell us which version