inverse color

S

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!
 
T

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:
 
?

=?ISO-8859-1?Q?G=F6ran_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
 
L

Larry Lard

Smokey said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top