65.9K
CodeProject is changing. Read more.
Home

Simple Method to Invert a Color

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.53/5 (5 votes)

Feb 22, 2015

CPOL
viewsIcon

18008

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();
Simple Method to Invert a Color - CodeProject