ImageAttributes.SetThreshold 方法

定義

設定臨界點 (透明度範圍)。Sets the threshold (transparency range).

多載

SetThreshold(Single)

設定預設分類的閾值 (透明度範圍)。Sets the threshold (transparency range) for the default category.

SetThreshold(Single, ColorAdjustType)

設定指定分類的閾值 (透明度範圍)。Sets the threshold (transparency range) for a specified category.

SetThreshold(Single)

設定預設分類的閾值 (透明度範圍)。Sets the threshold (transparency range) for the default category.

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

參數

threshold
Single

指定閾值的實數。A real number that specifies the threshold value.

範例

下列程式碼範例是針對與 Windows Forms 搭配使用所設計, 而且PaintEventArgs它需要e, 這Paint是事件處理常式的參數。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 該程式碼執行下列動作:The code performs the following actions:

  1. Image開啟, 並將它繪製到螢幕上。Opens an Image and draws it to the screen.

  2. 使用方法, 建立物件並設定其臨界值。 ImageAttributes SetThresholdCreates an ImageAttributes object and sets its threshold by using the SetThreshold method.

  3. 使用ImageAttributes物件的閾值, 將影像繪製到螢幕上。Draws the image to the screen by using the threshold of the ImageAttributes object.

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之間的值, 可指定每個色彩元件的截止點。The threshold is a value from 0 through 1 that specifies a cutoff point for each color component. 例如, 假設 [臨界值] 設定為 0.7, 而且假設您要轉譯色彩, 其紅色、綠色和藍色元件分別為230、50和220。For example, suppose the threshold is set to 0.7, and suppose you are rendering a color whose red, green, and blue components are 230, 50, and 220, respectively. 紅色元件 (230) 大於 0.7 x255, 因此紅色元件會變更為 255 (完整濃度)。The red component (230) is greater than 0.7x255, so the red component will be changed to 255 (full intensity). 綠色元件 (50) 小於 0.7 x255, 因此綠色元件會變更為0。The green component (50) is less than 0.7x255, so the green component will be changed to 0. 藍色元件 (220) 大於 0.7 x255, 因此藍色元件會變更為255。The blue component (220) is greater than 0.7x255, so the blue component will be changed to 255.

ImageAttributes物件會維護五個調整類別的色彩和灰階設定: 預設、點陣圖、筆刷、畫筆和文字。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 您可以指定預設分類的臨界值、點陣圖類別目錄的臨界值, 以及畫筆類別目錄的不同閾值。For example, you can specify a threshold for the default category, a threshold for the bitmap category, and still a different threshold for the pen category.

預設的彩色調整和灰階調整設定適用于沒有自己的調整設定的所有類別。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您從未針對 [畫筆] 分類指定任何調整設定, 則預設設定會套用至 [畫筆] 分類。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

SetThreshold(Single, ColorAdjustType)

設定指定分類的閾值 (透明度範圍)。Sets the threshold (transparency range) for a specified category.

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 之間,做為要對應至最大值或最小值的排序色彩中斷點。A threshold value from 0.0 to 1.0 that is used as a breakpoint to sort colors that will be mapped to either a maximum or a minimum value.

type
ColorAdjustType

ColorAdjustType 的元素,指定已經設定色彩閾值的分類。An element of ColorAdjustType that specifies the category for which the color threshold is set.

範例

如需程式碼範例, 請SetThreshold(Single)參閱方法。For a code example, see the SetThreshold(Single) method.

備註

閾值是介於0到1之間的值, 可指定每個色彩元件的截止點。The threshold is a value from 0 through 1 that specifies a cutoff point for each color component. 例如, 假設 [臨界值] 設定為 0.7, 而且假設您要轉譯色彩, 其紅色、綠色和藍色元件分別為230、50和220。For example, suppose the threshold is set to 0.7, and suppose you are rendering a color whose red, green, and blue components are 230, 50, and 220, respectively. 紅色元件 (230) 大於 0.7 x255, 因此紅色元件會變更為 255 (完整濃度)。The red component (230) is greater than 0.7x255, so the red component will be changed to 255 (full intensity). 綠色元件 (50) 小於 0.7 x255, 因此綠色元件會變更為0。The green component (50) is less than 0.7x255, so the green component will be changed to 0. 藍色元件 (220) 大於 0.7 x255, 因此藍色元件會變更為255。The blue component (220) is greater than 0.7x255, so the blue component will be changed to 255.

ImageAttributes物件會維護五個調整類別的色彩和灰階設定: 預設、點陣圖、筆刷、畫筆和文字。An ImageAttributes object maintains color and grayscale settings for five adjustment categories: default, bitmap, brush, pen, and text. 例如, 您可以指定預設分類的臨界值、點陣圖類別目錄的臨界值, 以及畫筆類別目錄的不同閾值。For example, you can specify a threshold for the default category, a threshold for the bitmap category, and still a different threshold for the pen category.

預設的彩色調整和灰階調整設定適用于沒有自己的調整設定的所有類別。The default color-adjustment and grayscale-adjustment settings apply to all categories that do not have adjustment settings of their own. 例如, 如果您從未針對 [畫筆] 分類指定任何調整設定, 則預設設定會套用至 [畫筆] 分類。For example, if you never specify any adjustment settings for the pen category, the default settings apply to the pen category.

當您指定特定分類的彩色調整或灰階調整設定時, 預設調整設定就不再適用于該類別。As soon as you specify a color-adjustment or grayscale-adjustment setting for a certain category, the default adjustment settings no longer apply to that category. 例如, 假設您為預設分類指定調整設定的集合。For example, suppose you specify a collection of adjustment settings for the default category. 如果您藉由傳遞Pen SetThreshold至方法來設定畫筆類別目錄的閾值, 則不會將任何預設的調整設定套用到畫筆。If you set the threshold for the pen category by passing Pen to the SetThreshold method, none of the default adjustment settings will apply to pens.

適用於