ImageAttributes 类 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含有关在呈现时如何操作位图和图元文件颜色的信息。
public ref class ImageAttributes sealed : ICloneable, IDisposablepublic sealed class ImageAttributes : ICloneable, IDisposabletype ImageAttributes = class
    interface ICloneable
    interface IDisposablePublic NotInheritable Class ImageAttributes
Implements ICloneable, IDisposable- 继承
- 
				ImageAttributes
- 实现
示例
以下示例采用 (0.2、0.0、0.4、1.0) 的所有一种颜色的图像,并将红色分量加 0.2 到红色、绿色和蓝色分量两倍。
下图左侧显示原始图像,右侧显示转换后的图像。
               
              
            
示例中的代码使用以下步骤执行重新着色:
- 初始化一个 ColorMatrix 对象。 
- 创建一个 ImageAttributes 对象并将 ColorMatrix 对象传递给 ImageAttributes 对象的 SetColorMatrix 方法。 
- 将 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 类的新实例。 |