[英]How can I draw an arc in C# WPF with parameters?
I would like to know how can I draw an arc in C# , I'm trying using DrawEllipse but it doesn't work and it give wrong drawing.我想知道如何在 C# 中绘制圆弧,我正在尝试使用 DrawEllipse 但它不起作用并且它给出了错误的绘图。 However, I have searched for a method to draw an arc in the Class DrawingContext but I didn't find it.但是,我在类 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 });
You would have to draw a PathGeometry
or a StreamGeometry
that contains an arc segment, like the following circular arc of radius 100 from (100,100) to (200,200):您必须绘制包含弧段的PathGeometry
或StreamGeometry
,如下面的半径为 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.