Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Simple Method to Invert a Color

0.00/5 (No votes)
21 Feb 2015 1  
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();

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here