ImageAttributes ImageAttributes ImageAttributes ImageAttributes Class

Definition

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

public ref class ImageAttributes sealed : ICloneable, IDisposable
public sealed class ImageAttributes : ICloneable, IDisposable
type ImageAttributes = class
    interface ICloneable
    interface IDisposable
Public NotInheritable Class ImageAttributes
Implements ICloneable, IDisposable
Inheritance
ImageAttributesImageAttributesImageAttributesImageAttributes
Implements

Examples

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);
Dim image As New Bitmap("InputColor.bmp")
Dim imageAttributes As New ImageAttributes()
Dim width As Integer = image.Width
Dim height As Integer = image.Height

' The following matrix consists of the following transformations:
' red scaling factor of 2
' green scaling factor of 1
' blue scaling factor of 1
' alpha scaling factor of 1
' three translations of 0.2
Dim colorMatrixElements As Single()() = { _
   New Single() {2, 0, 0, 0, 0}, _
   New Single() {0, 1, 0, 0, 0}, _
   New Single() {0, 0, 1, 0, 0}, _
   New Single() {0, 0, 0, 1, 0}, _
   New Single() {0.2F, 0.2F, 0.2F, 0, 1}}

Dim colorMatrix As 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), _
   0, _
   0, _
   width, _
   height, _
   GraphicsUnit.Pixel, _
   imageAttributes)

Remarks

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.

Constructors

ImageAttributes() ImageAttributes() ImageAttributes() ImageAttributes()

Initializes a new instance of the ImageAttributes class.

Methods

ClearBrushRemapTable() ClearBrushRemapTable() ClearBrushRemapTable() ClearBrushRemapTable()

Clears the brush color-remap table of this ImageAttributes object.

ClearColorKey() ClearColorKey() ClearColorKey() ClearColorKey()

Clears the color key (transparency range) for the default category.

ClearColorKey(ColorAdjustType) ClearColorKey(ColorAdjustType) ClearColorKey(ColorAdjustType) ClearColorKey(ColorAdjustType)

Clears the color key (transparency range) for a specified category.

ClearColorMatrix() ClearColorMatrix() ClearColorMatrix() ClearColorMatrix()

Clears the color-adjustment matrix for the default category.

ClearColorMatrix(ColorAdjustType) ClearColorMatrix(ColorAdjustType) ClearColorMatrix(ColorAdjustType) ClearColorMatrix(ColorAdjustType)

Clears the color-adjustment matrix for a specified category.

ClearGamma() ClearGamma() ClearGamma() ClearGamma()

Disables gamma correction for the default category.

ClearGamma(ColorAdjustType) ClearGamma(ColorAdjustType) ClearGamma(ColorAdjustType) ClearGamma(ColorAdjustType)

Disables gamma correction for a specified category.

ClearNoOp() ClearNoOp() ClearNoOp() ClearNoOp()

Clears the NoOp setting for the default category.

ClearNoOp(ColorAdjustType) ClearNoOp(ColorAdjustType) ClearNoOp(ColorAdjustType) ClearNoOp(ColorAdjustType)

Clears the NoOp setting for a specified category.

ClearOutputChannel() ClearOutputChannel() ClearOutputChannel() ClearOutputChannel()

Clears the CMYK (cyan-magenta-yellow-black) output channel setting for the default category.

ClearOutputChannel(ColorAdjustType) ClearOutputChannel(ColorAdjustType) ClearOutputChannel(ColorAdjustType) ClearOutputChannel(ColorAdjustType)

Clears the (cyan-magenta-yellow-black) output channel setting for a specified category.

ClearOutputChannelColorProfile() ClearOutputChannelColorProfile() ClearOutputChannelColorProfile() ClearOutputChannelColorProfile()

Clears the output channel color profile setting for the default category.

ClearOutputChannelColorProfile(ColorAdjustType) ClearOutputChannelColorProfile(ColorAdjustType) ClearOutputChannelColorProfile(ColorAdjustType) ClearOutputChannelColorProfile(ColorAdjustType)

Clears the output channel color profile setting for a specified category.

ClearRemapTable() ClearRemapTable() ClearRemapTable() ClearRemapTable()

Clears the color-remap table for the default category.

ClearRemapTable(ColorAdjustType) ClearRemapTable(ColorAdjustType) ClearRemapTable(ColorAdjustType) ClearRemapTable(ColorAdjustType)

Clears the color-remap table for a specified category.

ClearThreshold() ClearThreshold() ClearThreshold() ClearThreshold()

Clears the threshold value for the default category.

ClearThreshold(ColorAdjustType) ClearThreshold(ColorAdjustType) ClearThreshold(ColorAdjustType) ClearThreshold(ColorAdjustType)

Clears the threshold value for a specified category.

Clone() Clone() Clone() Clone()

Creates an exact copy of this ImageAttributes object.

Dispose() Dispose() Dispose() Dispose()

Releases all resources used by this ImageAttributes object.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize() Finalize() Finalize() Finalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.

GetAdjustedPalette(ColorPalette, ColorAdjustType) GetAdjustedPalette(ColorPalette, ColorAdjustType) GetAdjustedPalette(ColorPalette, ColorAdjustType) GetAdjustedPalette(ColorPalette, ColorAdjustType)

Adjusts the colors in a palette according to the adjustment settings of a specified category.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SetBrushRemapTable(ColorMap[]) SetBrushRemapTable(ColorMap[]) SetBrushRemapTable(ColorMap[]) SetBrushRemapTable(ColorMap[])

Sets the color-remap table for the brush category.

SetColorKey(Color, Color) SetColorKey(Color, Color) SetColorKey(Color, Color) SetColorKey(Color, Color)

Sets the color key for the default category.

SetColorKey(Color, Color, ColorAdjustType) SetColorKey(Color, Color, ColorAdjustType) SetColorKey(Color, Color, ColorAdjustType) SetColorKey(Color, Color, ColorAdjustType)

Sets the color key (transparency range) for a specified category.

SetColorMatrices(ColorMatrix, ColorMatrix) SetColorMatrices(ColorMatrix, ColorMatrix) SetColorMatrices(ColorMatrix, ColorMatrix) SetColorMatrices(ColorMatrix, ColorMatrix)

Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag)

Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType)

Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category.

SetColorMatrix(ColorMatrix) SetColorMatrix(ColorMatrix) SetColorMatrix(ColorMatrix) SetColorMatrix(ColorMatrix)

Sets the color-adjustment matrix for the default category.

SetColorMatrix(ColorMatrix, ColorMatrixFlag) SetColorMatrix(ColorMatrix, ColorMatrixFlag) SetColorMatrix(ColorMatrix, ColorMatrixFlag) SetColorMatrix(ColorMatrix, ColorMatrixFlag)

Sets the color-adjustment matrix for the default category.

SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType)

Sets the color-adjustment matrix for a specified category.

SetGamma(Single) SetGamma(Single) SetGamma(Single) SetGamma(Single)

Sets the gamma value for the default category.

SetGamma(Single, ColorAdjustType) SetGamma(Single, ColorAdjustType) SetGamma(Single, ColorAdjustType) SetGamma(Single, ColorAdjustType)

Sets the gamma value for a specified category.

SetNoOp() SetNoOp() SetNoOp() 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.

SetNoOp(ColorAdjustType) SetNoOp(ColorAdjustType) SetNoOp(ColorAdjustType) 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.

SetOutputChannel(ColorChannelFlag) SetOutputChannel(ColorChannelFlag) SetOutputChannel(ColorChannelFlag) SetOutputChannel(ColorChannelFlag)

Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.

SetOutputChannel(ColorChannelFlag, ColorAdjustType) SetOutputChannel(ColorChannelFlag, ColorAdjustType) SetOutputChannel(ColorChannelFlag, ColorAdjustType) SetOutputChannel(ColorChannelFlag, ColorAdjustType)

Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.

SetOutputChannelColorProfile(String) SetOutputChannelColorProfile(String) SetOutputChannelColorProfile(String) SetOutputChannelColorProfile(String)

Sets the output channel color-profile file for the default category.

SetOutputChannelColorProfile(String, ColorAdjustType) SetOutputChannelColorProfile(String, ColorAdjustType) SetOutputChannelColorProfile(String, ColorAdjustType) SetOutputChannelColorProfile(String, ColorAdjustType)

Sets the output channel color-profile file for a specified category.

SetRemapTable(ColorMap[]) SetRemapTable(ColorMap[]) SetRemapTable(ColorMap[]) SetRemapTable(ColorMap[])

Sets the color-remap table for the default category.

SetRemapTable(ColorMap[], ColorAdjustType) SetRemapTable(ColorMap[], ColorAdjustType) SetRemapTable(ColorMap[], ColorAdjustType) SetRemapTable(ColorMap[], ColorAdjustType)

Sets the color-remap table for a specified category.

SetThreshold(Single) SetThreshold(Single) SetThreshold(Single) SetThreshold(Single)

Sets the threshold (transparency range) for the default category.

SetThreshold(Single, ColorAdjustType) SetThreshold(Single, ColorAdjustType) SetThreshold(Single, ColorAdjustType) SetThreshold(Single, ColorAdjustType)

Sets the threshold (transparency range) for a specified category.

SetWrapMode(WrapMode) SetWrapMode(WrapMode) SetWrapMode(WrapMode) 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.

SetWrapMode(WrapMode, Color) SetWrapMode(WrapMode, Color) SetWrapMode(WrapMode, Color) 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.

SetWrapMode(WrapMode, Color, Boolean) SetWrapMode(WrapMode, Color, Boolean) SetWrapMode(WrapMode, Color, Boolean) 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.

ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to