Export (0) Print
Expand All

ImageAttributes Class

Contains information about how bitmap and metafile colors are manipulated during rendering.

System.Object
  System.Drawing.Imaging.ImageAttributes

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

public sealed class ImageAttributes : ICloneable, 
	IDisposable

The ImageAttributes type exposes the following members.

  NameDescription
Public methodImageAttributesInitializes a new instance of the ImageAttributes class.
Top

  NameDescription
Public methodClearBrushRemapTableClears the brush color-remap table of this ImageAttributes object.
Public methodClearColorKey()Clears the color key (transparency range) for the default category.
Public methodClearColorKey(ColorAdjustType)Clears the color key (transparency range) for a specified category.
Public methodClearColorMatrix()Clears the color-adjustment matrix for the default category.
Public methodClearColorMatrix(ColorAdjustType)Clears the color-adjustment matrix for a specified category.
Public methodClearGamma()Disables gamma correction for the default category.
Public methodClearGamma(ColorAdjustType)Disables gamma correction for a specified category.
Public methodClearNoOp()Clears the NoOp setting for the default category.
Public methodClearNoOp(ColorAdjustType)Clears the NoOp setting for a specified category.
Public methodClearOutputChannel()Clears the CMYK (cyan-magenta-yellow-black) output channel setting for the default category.
Public methodClearOutputChannel(ColorAdjustType)Clears the (cyan-magenta-yellow-black) output channel setting for a specified category.
Public methodClearOutputChannelColorProfile()Clears the output channel color profile setting for the default category.
Public methodClearOutputChannelColorProfile(ColorAdjustType)Clears the output channel color profile setting for a specified category.
Public methodClearRemapTable()Clears the color-remap table for the default category.
Public methodClearRemapTable(ColorAdjustType)Clears the color-remap table for a specified category.
Public methodClearThreshold()Clears the threshold value for the default category.
Public methodClearThreshold(ColorAdjustType)Clears the threshold value for a specified category.
Public methodCloneCreates an exact copy of this ImageAttributes object.
Public methodDisposeReleases all resources used by this ImageAttributes object.
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetAdjustedPaletteAdjusts the colors in a palette according to the adjustment settings of a specified category.
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSetBrushRemapTableSets the color-remap table for the brush category.
Public methodSetColorKey(Color, Color)Sets the color key for the default category.
Public methodSetColorKey(Color, Color, ColorAdjustType)Sets the color key (transparency range) for a specified category.
Public methodSetColorMatrices(ColorMatrix, ColorMatrix)Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.
Public methodSetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag)Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.
Public methodSetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType)Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category.
Public methodSetColorMatrix(ColorMatrix)Sets the color-adjustment matrix for the default category.
Public methodSetColorMatrix(ColorMatrix, ColorMatrixFlag)Sets the color-adjustment matrix for the default category.
Public methodSetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType)Sets the color-adjustment matrix for a specified category.
Public methodSetGamma(Single)Sets the gamma value for the default category.
Public methodSetGamma(Single, ColorAdjustType)Sets the gamma value for a specified category.
Public methodSetNoOp()Turns off color adjustment for the default category. You can call the ClearNoOp method to reinstate the color-adjustment settings that were in place before the call to the SetNoOp method.
Public methodSetNoOp(ColorAdjustType)Turns off color adjustment for a specified category. You can call the ClearNoOp method to reinstate the color-adjustment settings that were in place before the call to the SetNoOp method.
Public methodSetOutputChannel(ColorChannelFlag)Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.
Public methodSetOutputChannel(ColorChannelFlag, ColorAdjustType)Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.
Public methodSetOutputChannelColorProfile(String)Sets the output channel color-profile file for the default category.
Public methodSetOutputChannelColorProfile(String, ColorAdjustType)Sets the output channel color-profile file for a specified category.
Public methodSetRemapTable(ColorMap[])Sets the color-remap table for the default category.
Public methodSetRemapTable(ColorMap[], ColorAdjustType)Sets the color-remap table for a specified category.
Public methodSetThreshold(Single)Sets the threshold (transparency range) for the default category.
Public methodSetThreshold(Single, ColorAdjustType)Sets the threshold (transparency range) for a specified category.
Public methodSetWrapMode(WrapMode)Sets the wrap mode that is used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.
Public methodSetWrapMode(WrapMode, Color)Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.
Public methodSetWrapMode(WrapMode, Color, Boolean)Sets the wrap mode and color used to decide how to tile a texture across a shape, or at shape boundaries. A texture is tiled across a shape to fill it in when the texture is smaller than the shape it is filling.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

An ImageAttributes object maintains several color-adjustment settings, including color-adjustment matrices, grayscale-adjustment matrices, gamma-correction values, color-map tables, and color-threshold values. During rendering, colors can be corrected, darkened, lightened, and removed. To apply such manipulations, initialize an ImageAttributes object and pass the path of that ImageAttributes object (along with the path of an Image) to the DrawImage method.

The following example takes an image that is all one color (0.2, 0.0, 0.4, 1.0) and doubles the red component adds 0.2 to the red, green, and blue components

The following illustration shows the original image on the left and the transformed image on the right.

Colors

The code in the following example uses the following steps to perform the recoloring:

  1. Initialize a ColorMatrix object.

  2. Create an ImageAttributes object and pass the ColorMatrix object to the SetColorMatrix method of the ImageAttributes object.

  3. Pass the ImageAttributes object to the DrawImage method of a Graphics object.

Image image = new Bitmap("InputColor.bmp");
ImageAttributes imageAttributes = new ImageAttributes();
int width = image.Width;
int height = image.Height;

float[][] colorMatrixElements = { 
   new float[] {2,  0,  0,  0, 0},        // red scaling factor of 2 
   new float[] {0,  1,  0,  0, 0},        // green scaling factor of 1 
   new float[] {0,  0,  1,  0, 0},        // blue scaling factor of 1 
   new float[] {0,  0,  0,  1, 0},        // alpha scaling factor of 1 
   new float[] {.2f, .2f, .2f, 0, 1}};    // three translations of 0.2

ColorMatrix colorMatrix = new ColorMatrix(colorMatrixElements);

imageAttributes.SetColorMatrix(
   colorMatrix,
   ColorMatrixFlag.Default,
   ColorAdjustType.Bitmap);

e.Graphics.DrawImage(image, 10, 10);

e.Graphics.DrawImage(
   image,
   new Rectangle(120, 10, width, height),  // destination rectangle 
   0, 0,        // upper-left corner of source rectangle 
   width,       // width of source rectangle
   height,      // height of source rectangle
   GraphicsUnit.Pixel,
   imageAttributes);

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft