ImageAttributes 类

定义

包含有关在呈现时如何操作位图和图元文件颜色的信息。

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.2 到红色、绿色和蓝色分量。

下图左侧显示原始图像,右侧显示转换后的图像。

颜色

示例中的代码使用以下步骤执行重新着色:

  1. 初始化一个 ColorMatrix 对象。

  2. 创建一个 ImageAttributes 对象并将 ColorMatrix 对象传递给 ImageAttributes 对象的 SetColorMatrix 方法。

  3. ImageAttributes 对象传递给 Graphics 对象的 DrawImage 方法。

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 维护多个颜色调整设置,包括颜色调整矩阵、灰度调整矩阵、伽玛校正值、颜色映射表和颜色阈值。 在呈现过程中,可以更正、变暗、变浅和删除颜色。 若要应用此类操作,请初始化对象 ImageAttributes ,并将该 ImageAttributes 对象的路径 (以及) 的路径 Image 传递到 DrawImage 方法。

注意

在 .NET 6 及更高版本中, System.Drawing.Common 包(包括此类型)仅在 Windows 操作系统上受支持。 在跨平台应用中使用此类型会导致编译时警告和运行时异常。 有关详细信息,请参阅 仅在 Windows 上支持 System.Drawing.Common

构造函数

ImageAttributes()

初始化 ImageAttributes 类的新实例。

方法

ClearBrushRemapTable()

清除该 ImageAttributes 对象的画笔颜色重新映射表。

ClearColorKey()

为默认类别清除颜色键(透明范围)。

ClearColorKey(ColorAdjustType)

为指定类别清除颜色键(透明范围)。

ClearColorMatrix()

为默认类别清除颜色调整矩阵。

ClearColorMatrix(ColorAdjustType)

清除指定类别的颜色调整矩阵。

ClearGamma()

为默认类别禁用灰度校正。

ClearGamma(ColorAdjustType)

为指定类别禁用灰度校正。

ClearNoOp()

清除默认类别的 NoOp 设置。

ClearNoOp(ColorAdjustType)

清除指定类别的 NoOp 设置。

ClearOutputChannel()

为默认类别清除 CMYK(青色-洋红色-黄色-黑色)输出通道设置。

ClearOutputChannel(ColorAdjustType)

为指定类别清除(青色-洋红色-黄色-黑色)输出通道设置。

ClearOutputChannelColorProfile()

为默认类别清除输出通道颜色配置文件设置。

ClearOutputChannelColorProfile(ColorAdjustType)

为指定类别清除输出通道颜色配置文件设置。

ClearRemapTable()

为默认类别清除颜色重新映射表。

ClearRemapTable(ColorAdjustType)

为指定类别清除颜色重新映射表。

ClearThreshold()

为默认类别清除阈值。

ClearThreshold(ColorAdjustType)

为指定类别清除阈值。

Clone()

创建此 ImageAttributes 对象的一个精确副本。

Dispose()

释放由此 ImageAttributes 对象使用的所有资源。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Finalize()

在垃圾回收将某一对象回收前允许该对象尝试释放资源并执行其他清理操作。

GetAdjustedPalette(ColorPalette, ColorAdjustType)

根据指定类别的调整设置,调整调色板中的颜色。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

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

为画笔类别设置颜色重新映射表。

SetBrushRemapTable(ReadOnlySpan<ColorMap>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetBrushRemapTable(ReadOnlySpan<ValueTuple<Color,Color>>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetColorKey(Color, Color)

为默认类别设置颜色键。

SetColorKey(Color, Color, ColorAdjustType)

为指定类别设置颜色键(透明范围)。

SetColorMatrices(ColorMatrix, ColorMatrix)

为默认类别设置颜色调整矩阵和灰度调整矩阵。

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag)

为默认类别设置颜色调整矩阵和灰度调整矩阵。

SetColorMatrices(ColorMatrix, ColorMatrix, ColorMatrixFlag, ColorAdjustType)

为指定类别设置颜色调整矩阵和灰度调整矩阵。

SetColorMatrix(ColorMatrix)

为默认类别设置颜色调整矩阵。

SetColorMatrix(ColorMatrix, ColorMatrixFlag)

为默认类别设置颜色调整矩阵。

SetColorMatrix(ColorMatrix, ColorMatrixFlag, ColorAdjustType)

为指定类别设置颜色调整矩阵。

SetGamma(Single)

为默认类别设置伽玛值。

SetGamma(Single, ColorAdjustType)

为指定类别设置伽玛值。

SetNoOp()

为默认类别关闭颜色调整。 可以调用 ClearNoOp 方法恢复在调用 SetNoOp 方法前已存在的颜色调整设置。

SetNoOp(ColorAdjustType)

为指定类别关闭颜色调整。 可以调用 ClearNoOp 方法恢复在调用 SetNoOp 方法前已存在的颜色调整设置。

SetOutputChannel(ColorChannelFlag)

为默认类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。

SetOutputChannel(ColorChannelFlag, ColorAdjustType)

为指定的类别设置 CMYK(青色-洋红色-黄色-黑色)输出通道。

SetOutputChannelColorProfile(String)

为默认类别设置输出通道颜色配置文件。

SetOutputChannelColorProfile(String, ColorAdjustType)

为指定类别设置输出通道颜色配置文件。

SetRemapTable(ColorAdjustType, ReadOnlySpan<ColorMap>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetRemapTable(ColorAdjustType, ReadOnlySpan<ValueTuple<Color,Color>>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetRemapTable(ColorMap[])

为默认类别设置颜色重新映射表。

SetRemapTable(ColorMap[], ColorAdjustType)

为指定类别设置颜色重新映射表。

SetRemapTable(ReadOnlySpan<ColorMap>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetRemapTable(ReadOnlySpan<ValueTuple<Color,Color>>)

包含有关在呈现时如何操作位图和图元文件颜色的信息。

SetThreshold(Single)

为默认类别设置阈值(透明范围)。

SetThreshold(Single, ColorAdjustType)

为指定类别设置阈值(透明范围)。

SetWrapMode(WrapMode)

设置环绕模式,该模式用于决定如何将纹理平铺到一个形状上或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

SetWrapMode(WrapMode, Color)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

SetWrapMode(WrapMode, Color, Boolean)

设置环绕模式和颜色,用于决定如何将纹理平铺到一个形状上,或平铺到形状的边界上。 当纹理小于它所填充的形状时,纹理在该形状上平铺以填满该形状。

ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅