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 Create 物件,ColorMatrix並將 對象傳遞至 SetColorMatrix 物件的方法ImageAttributes

  3. ImageAttributes 對象傳遞至 DrawImage 物件的方法 Graphics

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 色彩調整設定,包括色彩調整矩陣、灰階調整矩陣、gamma-校正值、色彩對應表和色彩臨界值。 在轉譯期間,色彩可以更正、變暗、變淺和移除。 若要套用這類操作,請初始化 ImageAttributes 物件,並將該 ImageAttributes 對象的路徑連同) 的路徑 Image 傳遞至 DrawImage 方法 (。

注意

在 .NET 6 和更新版本中,只有 Windows 作業系統才支援包含此類型的 System.Drawing.Common 套件。 在跨平臺應用程式中使用此類型會導致編譯時間警告和運行時間例外狀況。 如需詳細資訊,請參閱 僅限 Windows 上支援的 System.Drawing.Common

建構函式

ImageAttributes()

初始化 ImageAttributes 類別的新執行個體。

方法

ClearBrushRemapTable()

清除此 ImageAttributes 物件的筆刷色彩重新對應表。

ClearColorKey()

清除預設分類的色鍵 (透明度範圍)。

ClearColorKey(ColorAdjustType)

清除指定分類的色鍵 (透明度範圍)。

ClearColorMatrix()

清除預設分類的彩色調整矩陣。

ClearColorMatrix(ColorAdjustType)

清除指定分類的彩色調整矩陣。

ClearGamma()

停用預設分類的 Gamma 修正。

ClearGamma(ColorAdjustType)

停用指定分類的 Gamma 修正。

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)

設定預設分類的 Gamma 值。

SetGamma(Single, ColorAdjustType)

設定指定分類的 Gamma 值。

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)

適用於

另請參閱