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 窗体一起使用,并且它需要 PaintEventArgse,它是 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. 使用 SetThreshold 方法创建 ImageAttributes 对象并设置其阈值。Creates 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.

适用于