ImageAttributes.SetThreshold 方法   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
设置阈值(透明度范围)。
重载
| SetThreshold(Single) | 设置默认类别的阈值(透明度范围)。 | 
| SetThreshold(Single, ColorAdjustType) | 设置指定类别的阈值(透明度范围)。 | 
SetThreshold(Single)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
设置默认类别的阈值(透明度范围)。
public:
 void SetThreshold(float threshold);public void SetThreshold (float threshold);member this.SetThreshold : single -> unitPublic Sub SetThreshold (threshold As Single)参数
- threshold
- Single
一个指定阈值的实数。
示例
下面的代码示例设计用于 Windows 窗体,它需要 PaintEventArgse,这是 Paint 事件处理程序的参数。 该代码执行以下操作:
- 打开 Image 并将其绘制到屏幕。 
- 创建一个 ImageAttributes 对象,并使用 SetThreshold 方法设置其阈值。 
- 使用 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)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- 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 -> unitPublic 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 对象维护五个调整类别的颜色和灰度设置:默认、位图、画笔、笔和文本。 例如,可以为默认类别指定阈值、位图类别的阈值,以及笔类别的阈值。
默认颜色调整和灰度调整设置适用于没有自己调整设置的所有类别。 例如,如果从未为笔类别指定任何调整设置,则默认设置将应用于笔类别。
指定特定类别的颜色调整或灰度调整设置后,默认调整设置将不再应用于该类别。 例如,假设为默认类别指定调整设置的集合。 如果将 Pen 传递给 SetThreshold 方法来设置笔类别的阈值,则默认调整设置将不适用于笔。