繁体   English   中英

如何使用参数在 C# WPF 中绘制圆弧?

[英]How can I draw an arc in C# WPF with parameters?

我想知道如何在 C# 中绘制圆弧,我正在尝试使用 DrawEllipse 但它不起作用并且它给出了错误的绘图。 但是,我在类 DrawingContext 中搜索了一种绘制圆弧的方法,但没有找到。

            DrawingVisual d = new DrawingVisual();

            System.Windows.Media.Pen pen = new System.Windows.Media.Pen();
            DrawingContext drawingContext = d.RenderOpen();

            pen.Brush = System.Windows.Media.Brushes.Black;
            System.Windows.Point center = new System.Windows.Point();
            center.X = 0.4;
            center.Y = 0.5;

            drawingContext.DrawEllipse(System.Windows.Media.Brushes.White, pen, center, 4,4);
            drawingContext.Close();
            canvas.Children.Add(new VisualHost { Visual = d });

您必须绘制包含弧段的PathGeometryStreamGeometry ,如下面的半径为 100 的圆弧从 (100,100) 到 (200,200):

var visual = new DrawingVisual();
var pen = new Pen(Brushes.Black, 1);

using (var dc = visual.RenderOpen())
{
    var figure = new PathFigure
    {
        StartPoint = new Point(100, 100) // start point
    };

    figure.Segments.Add(new ArcSegment
    {
        Point = new Point(200, 200), // end point
        Size = new Size(100, 100),   // radii
        SweepDirection = SweepDirection.Clockwise
    });

    var geometry = new PathGeometry();
    geometry.Figures.Add(figure);

    dc.DrawGeometry(null, pen, geometry);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM