Simple Method to Invert a Color






4.53/5 (5 votes)
A method to get the inverted equivalent of a specified color.
Introduction
This method accepts a System.Drawing.Color object and uses the RGB values to create and return an object representing the color's inversion.
public static Color Invert (this Color color) { return Color.FromArgb(255 - color.R, 255 - color.G, 255 - color.B); }
In this example the method is static and is an extension method so you can call it like so:
Color redInverted = Color.Red.Invert();