ImageAttributes.SetThreshold 方法

定義

設定閾值 (透明度範圍)。

多載

SetThreshold(Single)

設定預設分類的閾值 (透明度範圍)。

SetThreshold(Single, ColorAdjustType)

設定指定分類的閾值 (透明度範圍)。

SetThreshold(Single)

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

設定預設分類的閾值 (透明度範圍)。

public:
 void SetThreshold(float threshold);
public void SetThreshold (float threshold);
member this.SetThreshold : single -> unit
Public Sub SetThreshold (threshold As Single)

參數

threshold
Single

指定閾值的實數。

範例

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

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

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

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

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 = gcnew ImageAttributes;
   imageAttr->SetThreshold( 0.7f );

   // Draw the image with the colors bifurcated.
   Rectangle rect = Rectangle(300,20,200,200);
   e->Graphics->DrawImage( myImage, rect, 0, 0, 200, 200, GraphicsUnit::Pixel, imageAttr );
}
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);    
}
Public Sub SetThresholdExample(ByVal e As PaintEventArgs)

    ' Open an Image file, and draw it to the screen.
    Dim myImage As Image = Image.FromFile("Camera.jpg")
    e.Graphics.DrawImage(myImage, 20, 20)

    ' Create an ImageAttributes object, and set its color threshold.
    Dim imageAttr As New ImageAttributes
    imageAttr.SetThreshold(0.7F)

    ' Draw the image with the colors bifurcated.
    Dim rect As New Rectangle(300, 20, 200, 200)
    e.Graphics.DrawImage(myImage, rect, 0, 0, 200, 200, _
    GraphicsUnit.Pixel, imageAttr)
End Sub

備註

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

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

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

適用於

SetThreshold(Single, ColorAdjustType)

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

設定指定分類的閾值 (透明度範圍)。

public:
 void SetThreshold(float threshold, System::Drawing::Imaging::ColorAdjustType type);
public void SetThreshold (float threshold, System.Drawing.Imaging.ColorAdjustType type);
member this.SetThreshold : single * System.Drawing.Imaging.ColorAdjustType -> unit
Public Sub SetThreshold (threshold As Single, type As ColorAdjustType)

參數

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 調整類別的色彩和灰階設定:預設、點陣圖、筆刷、畫筆和文字。 例如,您可以指定預設類別的臨界值、點陣圖類別的臨界值,以及畫筆類別的臨界值仍然不同。

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

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

適用於