ImageAttributes.SetThreshold 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
设置阈值(透明范围)。
重载
SetThreshold(Single) |
为默认类别设置阈值(透明范围)。 |
SetThreshold(Single, ColorAdjustType) |
为指定类别设置阈值(透明范围)。 |
SetThreshold(Single)
- Source:
- ImageAttributes.cs
- Source:
- ImageAttributes.cs
- Source:
- 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 窗体 一起使用,它需要 PaintEventArgse
,它是 事件处理程序的Paint一个参数。 此代码执行以下操作:
Image打开 并将其绘制到屏幕。
使用 SetThreshold 方法创建对象ImageAttributes并设置其阈值。
使用 对象的阈值 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
为指定类别设置阈值(透明范围)。
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 方法来设置笔类别的阈值,则任何默认调整设置都不会应用于笔。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈