Export (0) Print
Expand All

Graphics.GetNearestColor Method

Gets the nearest color to the specified Color structure.

Namespace:  System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

member GetNearestColor : 
        color:Color -> Color

Parameters

color
Type: System.Drawing.Color

Color structure for which to find a match.

Return Value

Type: System.Drawing.Color
A Color structure that represents the nearest color to the one specified with the color parameter.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgs e, which is a parameter of the Paint event handler. The code performs the following actions:

  • Creates an arbitrary color with ARGB coordinates (255, 165, 63, 136).

  • Creates a solid brush and sets its color to the specified color.

  • Fills an ellipse using the arbitrary color.

  • Creates a second color and sets its value to the nearest system ARGB color.

  • Fills a second ellipse with this color.

The result is two ellipses: the first drawn with the arbitrary specified color and the second drawn with the system color nearest the specified color.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft