ImageAttributes.SetThreshold 方法

定義

設定臨界值(透明度範圍)。

多載

SetThreshold(Single)

設定預設類別的臨界值(透明度範圍)。

SetThreshold(Single, ColorAdjustType)

設定指定類別的臨界值(透明度範圍)。

SetThreshold(Single)

來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs

設定預設類別的臨界值(透明度範圍)。

C#
public void SetThreshold (float threshold);

參數

threshold
Single

指定臨界值的實數。

範例

下列程式代碼範例是專為搭配 Windows Forms 使用而設計,而且需要 PaintEventArgse,這是 Paint 事件處理程式的參數。 程式代碼會執行下列動作:

  1. 開啟 Image 並將它繪製到畫面。

  2. 建立 ImageAttributes 物件,並使用 SetThreshold 方法來設定其臨界值。

  3. 使用 ImageAttributes 物件的閾值,將影像繪製到畫面。

C#
private void SetThresholdExample(PaintEventArgs e)
{
             
    // Open an Image file, and draw it to the screen.
    Image myImage = Image.FromFile("Camera.jpg");
    e.Graphics.DrawImage(myImage, 20, 20);
             
    // Create an ImageAttributes object, and set its color threshold.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetThreshold(0.7f);
             
    // Draw the image with the colors bifurcated.
    Rectangle rect = new Rectangle(300, 20, 200, 200);
    e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, 
        GraphicsUnit.Pixel, imageAttr);    
}

備註

臨界值是從 0 到 1 的值,指定每個色彩元件的截止點。 例如,假設臨界值設定為0.7,並假設您呈現的是紅色、綠色和藍色元件分別為230、50和220的色彩。 紅色元件 (230) 大於 0.7x255,因此紅色元件會變更為 255 (完整強度)。 綠色元件 (50) 小於 0.7x255,因此綠色元件會變更為 0。 藍色元件 (220) 大於 0.7x255,因此藍色元件會變更為 255。

ImageAttributes 物件會維護五個調整類別的色彩和灰階設定:預設、位圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的臨界值、位圖類別的臨界值,以及畫筆類別的臨界值。

默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

SetThreshold(Single, ColorAdjustType)

來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs
來源:
ImageAttributes.cs

設定指定類別的臨界值(透明度範圍)。

C#
public void SetThreshold (float threshold, System.Drawing.Imaging.ColorAdjustType type);

參數

threshold
Single

從 0.0 到 1.0 的臨界值,用來做為斷點來排序將對應至最大值或最小值的色彩。

type
ColorAdjustType

ColorAdjustType 的 元素,指定設定色彩閾值的類別。

範例

如需程式代碼範例,請參閱 SetThreshold(Single) 方法。

備註

臨界值是從 0 到 1 的值,指定每個色彩元件的截止點。 例如,假設臨界值設定為0.7,並假設您呈現的是紅色、綠色和藍色元件分別為230、50和220的色彩。 紅色元件 (230) 大於 0.7x255,因此紅色元件會變更為 255 (完整強度)。 綠色元件 (50) 小於 0.7x255,因此綠色元件會變更為 0。 藍色元件 (220) 大於 0.7x255,因此藍色元件會變更為 255。

ImageAttributes 物件會維護五個調整類別的色彩和灰階設定:預設、位圖、筆刷、手寫筆和文字。 例如,您可以指定預設類別的臨界值、位圖類別的臨界值,以及畫筆類別的臨界值。

默認色彩調整和灰階調整設定適用於沒有自己調整設定的所有類別。 例如,如果您從未指定畫筆類別的任何調整設定,則預設設定會套用至畫筆類別。

一旦您指定特定類別的色彩調整或灰階調整設定,預設調整設定就不再套用至該類別。 例如,假設您指定預設類別的調整設定集合。 如果您藉由將 Pen 傳遞至 SetThreshold 方法來設定畫筆類別的閾值,則默認調整設定都不會套用至畫筆。

適用於

.NET 9 及其他版本
產品 版本
.NET 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9