ImageAttributes Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
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
-
ImageAttributes
- 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.
The code in the example uses the following steps to perform the recoloring:
Initialize a ColorMatrix object.
Create an ImageAttributes object and pass the ColorMatrix object to the SetColorMatrix method of the ImageAttributes object.
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.
Note
In .NET 6 and later versions, the System.Drawing.Common package, which includes this type, is only supported on Windows operating systems. Use of this type in cross-platform apps causes compile-time warnings and run-time exceptions. For more information, see System.Drawing.Common only supported on Windows.
Constructors
ImageAttributes() |
Initializes a new instance of the ImageAttributes class. |
Methods
ClearBrushRemapTable() |
Clears the brush color-remap table of this ImageAttributes object. |
ClearColorKey() |
Clears the color key (transparency range) for the default category. |
ClearColorKey(ColorAdjustType) |
Clears the color key (transparency range) for a specified category. |
ClearColorMatrix() |
Clears the color-adjustment matrix for the default category. |
ClearColorMatrix(ColorAdjustType) |
Clears the color-adjustment matrix for a specified category. |
ClearGamma() |
Disables gamma correction for the default category. |
ClearGamma(ColorAdjustType) |
Disables gamma correction for a specified category. |
ClearNoOp() |
Clears the |
ClearNoOp(ColorAdjustType) |
Clears the |
ClearOutputChannel() |
Clears the CMYK (cyan-magenta-yellow-black) output channel setting for the default category. |
ClearOutputChannel(ColorAdjustType) |
Clears the (cyan-magenta-yellow-black) output channel setting for a specified category. |
ClearOutputChannelColorProfile() |
Clears the output channel color profile setting for the default category. |
ClearOutputChannelColorProfile(ColorAdjustType) |
Clears the output channel color profile setting for a specified category. |
ClearRemapTable() |
Clears the color-remap table for the default category. |
ClearRemapTable(ColorAdjustType) |
Clears the color-remap table for a specified category. |
ClearThreshold() |
Clears the threshold value for the default category. |
ClearThreshold(ColorAdjustType) |
Clears the threshold value for a specified category. |
Clone() |
Creates an exact copy of this ImageAttributes object. |
Dispose() |
Releases all resources used by this ImageAttributes object. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Finalize() |
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. |
GetAdjustedPalette(ColorPalette, ColorAdjustType) |
Adjusts the colors in a palette according to the adjustment settings of a specified category. |
GetHashCode() |
Serves as the default hash function. (Inherited from Object) |
GetType() |
Gets the Type of the current instance. (Inherited from Object) |
MemberwiseClone() |
Creates a shallow copy of the current Object. (Inherited from Object) |
SetBrushRemapTable(ColorMap[]) |
Sets the color-remap table for the brush category. |
SetBrushRemapTable(ReadOnlySpan<ColorMap>) |
Sets the color-remap table for a specified category. |
SetBrushRemapTable(ReadOnlySpan<ValueTuple<Color,Color>>) |
Sets the color-remap table for a specified category. |
SetColorKey(Color, Color, ColorAdjustType) |
Sets the color key (transparency range) for a specified category. |
SetColorKey(Color, Color) |
Sets the color key for the default category. |
SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType) |
Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category. |
SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag) |
Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category. |
SetColorMatrices(ColorMatrix, ColorMatrix) |
Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category. |
SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType) |
Sets the color-adjustment matrix for a specified category. |
SetColorMatrix(ColorMatrix, ColorMatrixFlag) |
Sets the color-adjustment matrix for the default category. |
SetColorMatrix(ColorMatrix) |
Sets the color-adjustment matrix for the default category. |
SetGamma(Single, ColorAdjustType) |
Sets the gamma value for a specified category. |
SetGamma(Single) |
Sets the gamma value for the default category. |
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) |
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, ColorAdjustType) |
Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category. |
SetOutputChannel(ColorChannelFlag) |
Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category. |
SetOutputChannelColorProfile(String, ColorAdjustType) |
Sets the output channel color-profile file for a specified category. |
SetOutputChannelColorProfile(String) |
Sets the output channel color-profile file for the default category. |
SetRemapTable(ColorAdjustType, ReadOnlySpan<ColorMap>) |
Sets the color-remap table for a specified category. |
SetRemapTable(ColorAdjustType, ReadOnlySpan<ValueTuple<Color,Color>>) |
Sets the color-remap table for a specified category. |
SetRemapTable(ColorMap[], ColorAdjustType) |
Sets the color-remap table for a specified category. |
SetRemapTable(ColorMap[]) |
Sets the color-remap table for the default category. |
SetRemapTable(ReadOnlySpan<ColorMap>) |
Sets the color-remap table for a specified category. |
SetRemapTable(ReadOnlySpan<ValueTuple<Color,Color>>) |
Sets the color-remap table for a specified category. |
SetThreshold(Single, ColorAdjustType) |
Sets the threshold (transparency range) for a specified category. |
SetThreshold(Single) |
Sets the threshold (transparency range) for the default category. |
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. |
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) |
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. |
ToString() |
Returns a string that represents the current object. (Inherited from Object) |