在笛卡尔图中填充两条曲线之间的空间

时间:2011-04-29 23:39:33

标签: c# graphics draw fill curve

在我的WinForms程序中,感觉卡特里亚图中两条曲线之间的空间有些困难。

基本上我有两条曲线,我使用这种方法在位图上绘制它们:

    public Bitmap DrawEnvelope(PointF[] u, PointF[] d)
    {
        g = Graphics.FromImage(box);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;

        Pen pengraph = new Pen(Color.FromArgb(50, 0 ,0 ,200), 1F);
        pengraph.Alignment = PenAlignment.Center;

        g.DrawCurve(pengraph, u, 0); //uperline
        g.DrawCurve(pengraph, d, 0); //downline

        g.Dispose();

        return box;
    }

现在我想用一种颜色填充这两条曲线之间的空间。怎么办呢?

我在MSDN中查找了一个像FillClosedCurve这样的方法。但在这种情况下它并没有帮助我。

感谢。

由Akh的评论解决

        joinedCurves.AddRange(u);
        joinedCurves.AddRange(d.Reverse());

        PointF[] fillPoints = joinedCurves.ToArray();
        SolidBrush fillBrush = new SolidBrush(Color.FromArgb(50, 0, 0, 200));
        FillMode newFillMode = FillMode.Alternate;

        g.FillClosedCurve(fillBrush, fillPoints, newFillMode, 0);

1 个答案:

答案 0 :(得分:1)

List<PointF> joinedCurves = new List<PointF>();
joinedCurves.AddRange(u);        
jointCurves.AddRange(d.Reverse());      
PointF[] fillPoints = joinedCurves.ToArray();    
SolidBrush fillBrush = new SolidBrush(Color.FromArgb(50, 0, 0, 200));    
FillMode newFillMode = FillMode.Alternate;    
g.FillClosedCurve(fillBrush, fillPoints, newFillMode, 0);