Graphics.GetNearestColor(Color) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取与指定的 Color 结构最接近的颜色。
public:
System::Drawing::Color GetNearestColor(System::Drawing::Color color);
public System.Drawing.Color GetNearestColor (System.Drawing.Color color);
member this.GetNearestColor : System.Drawing.Color -> System.Drawing.Color
Public Function GetNearestColor (color As Color) As Color
参数
返回
一个 Color 结构,它表示与 color
参数指定的颜色最接近的颜色。
示例
下面的代码示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse
,这是事件处理程序的参数Paint。 此代码执行以下操作:
使用 ARGB 坐标 (255、165、63、136) 创建任意颜色。
创建纯色画笔,并将其颜色设置为指定颜色。
使用任意颜色填充椭圆。
创建第二种颜色,并将其值设置为最接近的系统 ARGB 颜色。
用此颜色填充第二个椭圆。
结果为两个省略号:第一个省略号使用任意指定颜色绘制,第二个省略号使用最接近指定颜色的系统颜色绘制。
public:
void GetNearestColorColor( PaintEventArgs^ e )
{
// Create solid brush with arbitrary color.
Color arbColor = Color::FromArgb( 255, 165, 63, 136 );
SolidBrush^ arbBrush = gcnew SolidBrush( arbColor );
// Fill ellipse on screen.
e->Graphics->FillEllipse( arbBrush, 0, 0, 200, 100 );
// Get nearest color.
Color realColor = e->Graphics->GetNearestColor( arbColor );
SolidBrush^ realBrush = gcnew SolidBrush( realColor );
// Fill ellipse on screen.
e->Graphics->FillEllipse( realBrush, 0, 100, 200, 100 );
}
private void GetNearestColorColor(PaintEventArgs e)
{
// Create solid brush with arbitrary color.
Color arbColor = Color.FromArgb(255, 165, 63, 136);
SolidBrush arbBrush = new SolidBrush(arbColor);
// Fill ellipse on screen.
e.Graphics.FillEllipse(arbBrush, 0, 0, 200, 100);
// Get nearest color.
Color realColor = e.Graphics.GetNearestColor(arbColor);
SolidBrush realBrush = new SolidBrush(realColor);
// Fill ellipse on screen.
e.Graphics.FillEllipse(realBrush, 0, 100, 200, 100);
}
Private Sub GetNearestColorColor(ByVal e As PaintEventArgs)
' Create solid brush with arbitrary color.
Dim arbColor As Color = Color.FromArgb(255, 165, 63, 136)
Dim arbBrush As New SolidBrush(arbColor)
' Fill ellipse on screen.
e.Graphics.FillEllipse(arbBrush, 0, 0, 200, 100)
' Get nearest color.
Dim realColor As Color = e.Graphics.GetNearestColor(arbColor)
Dim realBrush As New SolidBrush(realColor)
' Fill ellipse on screen.
e.Graphics.FillEllipse(realBrush, 0, 100, 200, 100)
End Sub
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈