     Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar     MSDN Visual Basic Community   Title Invert an RGB color color, invert, RGB, complement Graphics

You can invert a color by subtracting each of its red, green, and blue components from 255. In other words:

```    new_red   = 255 - old_red
new_green = 255 - old_green
new_blue  = 255 - old_blue```

You can break a color into its components, use this technique to invert the components, and then use RGB to recombine them into the inverted color. However, there is a much simpler method.

If a color's components are given as R, G, and B, then the color is represented as:

`    R + 256 * G + 256 * 256 * B`

Now consider the representation of inverse of this color with components 255 - R, 255 - G, and 255 - B:

```    (255 - R) + 256 * (255 - G) + 256 * 256 * (255 - B)
= (255 + 256 * 255 + 256 * 256 * 255) -
(R + 256 * G + 256 * 256 * B)
= &HFFFFFF - the_original_color```

So a simpler method for calculating the inverse of a color is:

`    new_color = &HFFFFFF - old_color`  Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.  Updated 