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.2 新增至紅色、綠色和藍色元件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.

色彩Colors

下列範例中的程式碼會使用下列步驟來執行重新著色:The code in the following example uses the following steps to perform the recoloring:

  1. ColorMatrix初始化物件。Initialize a ColorMatrix object.

  2. 建立物件, 並將ColorMatrix物件傳遞ImageAttributesSetColorMatrix物件的方法。 ImageAttributesCreate an ImageAttributes object and pass the ColorMatrix object to the SetColorMatrix method of the ImageAttributes object.

  3. 將物件傳遞給Graphics物件DrawImage的方法。 ImageAttributesPass 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物件會維護數個顏色調整設定, 包括彩色調整矩陣、灰階調整矩陣、gamma 更正值、色彩對應表和色彩臨界值。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()

停用預設分類的 Gamma 修正。Disables gamma correction for the default category.

ClearGamma(ColorAdjustType)

停用指定分類的 Gamma 修正。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)

根據指定分類的調整設定來調整調色盤 (Palette) 中的色彩。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 的淺層複本 (Shallow Copy)。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)

設定預設分類的 Gamma 值。Sets the gamma value for the default category.

SetGamma(Single, ColorAdjustType)

設定指定分類的 Gamma 值。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)

設定環繞模式 (Wrap Mode),這個模式是用來決定如何橫越形狀或在形狀界限並排紋理。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()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

適用於

另請參閱