我在这个问题上坚持了几个小时,但似乎无法取得进展。
我有一个完美的环(图1),但是当我增加内椭圆时,我失去了绘图(图2)
我想我需要缩放Blend.Factor和/或Blend.Positions,但我不知道这样做。
这是我的因子和位置数组:
_Factors = new float[] { 0f, 1f, 0f, 0f };
_Positions = new float[] { 0f, 0.25f, 0.5f, 1f };
这是我的Paint功能:
using (Brush oInnerBrush = new SolidBrush(_InnerColor))
{
using (Pen oBaseBrush = new Pen(_BaseColor, 2))
{
using (GraphicsPath oGraphPath = new GraphicsPath())
{
// Outside
oGraphPath.AddEllipse(oRect);
// Inside
oGraphPath.AddEllipse(oRect.Shrink(_InnerWidth));
using (PathGradientBrush oGradBrush = new PathGradientBrush(oGraphPath))
{
Blend oBlend = new Blend();
oBlend.Factors = _Factors;
oBlend.Positions = _Positions;
oGradBrush.Blend = oBlend;
oGradBrush.CenterColor = ((SolidBrush)oInnerBrush).Color;
oGradBrush.SurroundColors = new Color[] { oBaseBrush.Color };
Area.FillPath(oGradBrush, oGraphPath);
}
}
}
}
有什么想法吗?谢谢。
编辑:我正在使用this question by BlueMonkMN
中的代码