ImageAttributes 类

定义

包含有关在呈现时如何操作位图和图元文件颜色的信息。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
继承
ImageAttributes
实现

示例

下面的示例使用一个图像,该图像是一种颜色(0.2、0.0、0.4、1.0),并使红色分量加倍,使红色、绿色和蓝色分量增加了0。2The 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. 初始化 ColorMatrix 的对象。Initialize a ColorMatrix object.

  2. 创建 ImageAttributes 对象并将 ColorMatrix 对象传递给 ImageAttributes 对象的 SetColorMatrix 方法。Create an ImageAttributes object and pass the ColorMatrix object to the SetColorMatrix method of the ImageAttributes object.

  3. ImageAttributes 对象传递到 Graphics 对象的 DrawImage 方法。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)

注解

ImageAttributes 对象维护多个颜色调整设置,包括颜色调整矩阵、灰度调整矩阵、伽玛矫正值、颜色映射表和颜色阈值。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. 若要应用此类操作,请初始化 ImageAttributes 对象,并将该 ImageAttributes 对象的路径(连同 Image的路径)传递到 DrawImage 方法。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.

构造函数

ImageAttributes()

初始化 ImageAttributes 类的新实例。Initializes a new instance of the ImageAttributes class.

方法

ClearBrushRemapTable()

清除该 ImageAttributes 对象的画笔颜色重新映射表。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()

清除默认类别的 NoOp 设置。Clears the NoOp setting for the default category.

ClearNoOp(ColorAdjustType)

清除指定类别的 NoOp 设置。Clears the NoOp setting for a specified category.

ClearOutputChannel()

为默认类别清除 CMYK(青色-洋红色-黄色-黑色)输出通道设置。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()

创建此 ImageAttributes 对象的一个精确副本。Creates an exact copy of this ImageAttributes object.

Dispose()

释放由此 ImageAttributes 对象使用的所有资源。Releases all resources used by this ImageAttributes object.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 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.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetBrushRemapTable(ColorMap[])

为画笔类别设置颜色重新映射表。Sets the color-remap table for the brush category.

SetColorKey(Color, Color)

为默认类别设置颜色键。Sets the color key for the default category.

SetColorKey(Color, Color, ColorAdjustType)

为指定类别设置颜色键(透明范围)。Sets the color key (transparency range) for a specified category.

SetColorMatrices(ColorMatrix, ColorMatrix)

为默认类别设置颜色调整矩阵和灰度调整矩阵。Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag)

为默认类别设置颜色调整矩阵和灰度调整矩阵。Sets the color-adjustment matrix and the grayscale-adjustment matrix for the default category.

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType)

为指定类别设置颜色调整矩阵和灰度调整矩阵。Sets the color-adjustment matrix and the grayscale-adjustment matrix for a specified category.

SetColorMatrix(ColorMatrix)

为默认类别设置颜色调整矩阵。Sets the color-adjustment matrix for the default category.

SetColorMatrix(ColorMatrix, ColorMatrixFlag)

为默认类别设置颜色调整矩阵。Sets the color-adjustment matrix for the default category.

SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType)

为指定类别设置颜色调整矩阵。Sets the color-adjustment matrix for a specified category.

SetGamma(Single)

为默认类别设置伽玛值。Sets the gamma value for the default category.

SetGamma(Single, ColorAdjustType)

为指定类别设置伽玛值。Sets the gamma value for a specified category.

SetNoOp()

为默认类别关闭颜色调整。Turns off color adjustment for the default category. 可以调用 ClearNoOp 方法恢复在调用 SetNoOp 方法前已存在的颜色调整设置。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. 可以调用 ClearNoOp 方法恢复在调用 SetNoOp 方法前已存在的颜色调整设置。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)

为默认类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for the default category.

SetOutputChannel(ColorChannelFlag, ColorAdjustType)

为指定的类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。Sets the CMYK (cyan-magenta-yellow-black) output channel for a specified category.

SetOutputChannelColorProfile(String)

为默认类别设置输出通道颜色配置文件。Sets the output channel color-profile file for the default category.

SetOutputChannelColorProfile(String, ColorAdjustType)

为指定类别设置输出通道颜色配置文件。Sets the output channel color-profile file for a specified category.

SetRemapTable(ColorMap[])

为默认类别设置颜色重新映射表。Sets the color-remap table for the default category.

SetRemapTable(ColorMap[], ColorAdjustType)

为指定类别设置颜色重新映射表。Sets the color-remap table for a specified category.

SetThreshold(Single)

为默认类别设置阈值(透明范围)。Sets the threshold (transparency range) for the default category.

SetThreshold(Single, ColorAdjustType)

为指定类别设置阈值(透明范围)。Sets the threshold (transparency range) for a specified category.

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)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。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)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。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()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)

适用于

另请参阅