This topic has not yet been rated - Rate this topic

ImageAttributes Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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.

  Name Description
Public method ImageAttributes Initializes a new instance of the ImageAttributes class.
Top
  Name Description
Public method ClearBrushRemapTable Clears the brush color-remap table of this ImageAttributes object.
Public method ClearColorKey() Clears the color key (transparency range) for the default category.
Public method ClearColorKey(ColorAdjustType) Clears the color key (transparency range) for a specified category.
Public method ClearColorMatrix() Clears the color-adjustment matrix for the default category.
Public method ClearColorMatrix(ColorAdjustType) Clears the color-adjustment matrix for a specified category.
Public method ClearGamma() Disables gamma correction for the default category.
Public method ClearGamma(ColorAdjustType) Disables gamma correction for a specified category.
Public method ClearNoOp() Clears the NoOp setting for the default category.
Public method ClearNoOp(ColorAdjustType) Clears the NoOp setting for a specified category.
Public method ClearOutputChannel() Clears the CMYK (cyan-magenta-yellow-black) output channel setting for the default category.
Public method ClearOutputChannel(ColorAdjustType) Clears the (cyan-magenta-yellow-black) output channel setting for a specified category.
Public method ClearOutputChannelColorProfile() Clears the output channel color profile setting for the default category.
Public method ClearOutputChannelColorProfile(ColorAdjustType) Clears the output channel color profile setting for a specified category.
Public method ClearRemapTable() Clears the color-remap table for the default category.
Public method ClearRemapTable(ColorAdjustType) Clears the color-remap table for a specified category.
Public method ClearThreshold() Clears the threshold value for the default category.
Public method ClearThreshold(ColorAdjustType) Clears the threshold value for a specified category.
Public method Clone Creates an exact copy of this ImageAttributes object.
Public method Dispose Releases all resources used by this ImageAttributes object.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetAdjustedPalette Adjusts the colors in a palette according to the adjustment settings of a specified category.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method SetBrushRemapTable Sets the color-remap table for the brush category.
Public method SetColorKey(Color, Color) Sets the color key for the default category.
Public method SetColorKey(Color, Color, ColorAdjustType) Sets the color key (transparency range) for a specified category.
Public method SetColorMatrices(ColorMatrix, ColorMatrix) Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.
Public method SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.
Public method SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category.
Public method SetColorMatrix(ColorMatrix) Sets the color-adjustment matrix for the default category.
Public method SetColorMatrix(ColorMatrix, ColorMatrixFlag) Sets the color-adjustment matrix for the default category.
Public method SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) Sets the color-adjustment matrix for a specified category.
Public method SetGamma(Single) Sets the gamma value for the default category.
Public method SetGamma(Single, ColorAdjustType) Sets the gamma value for a specified category.
Public method SetNoOp() 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 method SetNoOp(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 method SetOutputChannel(ColorChannelFlag) Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.
Public method SetOutputChannel(ColorChannelFlag, ColorAdjustType) Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.
Public method SetOutputChannelColorProfile(String) Sets the output channel color-profile file for the default category.
Public method SetOutputChannelColorProfile(String, ColorAdjustType) Sets the output channel color-profile file for a specified category.
Public method SetRemapTable(ColorMap[]) Sets the color-remap table for the default category.
Public method SetRemapTable(ColorMap[], ColorAdjustType) Sets the color-remap table for a specified category.
Public method SetThreshold(Single) Sets the threshold (transparency range) for the default category.
Public method SetThreshold(Single, ColorAdjustType) Sets the threshold (transparency range) for a specified category.
Public method SetWrapMode(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 method SetWrapMode(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 method SetWrapMode(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 method ToString Returns 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, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8 Consumer Preview, Windows Server 8 Beta, Windows 7, Windows Server 2008 SP2, 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.
Did you find this helpful?
(1500 characters remaining)