ImageAttributes.SetColorMatrix Method (ColorMatrix)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Sets the color-adjustment matrix for the default category.

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

member SetColorMatrix : 
        newColorMatrix:ColorMatrix -> unit


Type: System.Drawing.Imaging.ColorMatrix

The color-adjustment matrix.

An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. For example, you can specify a color-adjustment matrix for the default category, a different color-adjustment matrix for the bitmap category, and still a different color-adjustment matrix for the pen category.

The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

Calling the ImageAttributes.SetColorMatrix(ColorMatrix) method is equivalent to calling the ImageAttributes.SetColorMatrix(ColorMatrix, ColorMatrixFlag) method and passing ColorMatrixFlag.Default for the flags parameter. ColorMatrixFlag.Default specifies that all colors (including grays) are adjusted by the color-adjustment matrix

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:

  1. Creates a rectangle image that has all the color values set to 128, producing a rectangle that is filled with a solid medium-gray color. The code then draws this rectangle image to the screen.

  2. Creates a ColorMatrix and sets its Matrix location to 1.75, which emphasizes the red component of the image.

  3. Creates an ImageAttributes object and calls the SetColorMatrix method.

  4. Draws the image (a second rectangle) to the screen using the ColorMatrix just set in the ImageAttributes object.

Note that the second rectangle has the color red emphasized.

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

.NET Framework
Available since 1.1
Return to top