在Xaml UWP渲染中,System.Drawing.Drawing2D.GraphicsPath.AddArc是否有任何等价物?
据我所知,我在XAML UWP中尝试过以下用例 .
Path path = new Path();
PathGeometry pathGeometry = new PathGeometry();
PathFigure pathFigure = new PathFigure();
ArcSegment arcSegment = new ArcSegment();
arcSegment.IsLargeArc = true;
arcSegment.Size = new Windows.Foundation.Size(100, 100);
arcSegment.Point = new Windows.Foundation.Point(100, 100);
arcSegment.RotationAngle = 180;
arcSegment.SweepDirection = SweepDirection.Clockwise;
pathFigure.StartPoint = new Windows.Foundation.Point(100, 100);
pathFigure.Segments.Add(arcSegment);
path.Data = pathGeometry;
path.Fill = new SolidColorBrush(Colors.Red);
path.StrokeThickness = 2;
pathGeometry.Figures.Add(pathFigure);
但以上并非100%相当于System.Drawing.Drawing2D.GraphicsPath.AddArc(Rectangle, Single, Single)
1 回答
在经典的Windows窗体应用程序中,我们有System.Drawing.Drawing2D名称空间用于绘制图形 . 但是UWP应用程序不支持此命名空间 . UWP应用程序有自己的绘制图形的API . 您应该能够在Windows.UI.Xaml.Shapes命名空间下通过API绘制形状 . 有关如何在uwp应用程序上绘制形状的更多详细信息,请参阅this article .
方法
System.Drawing.Drawing2D.GraphicsPath.AddArc
实际上用于绘制弧,您已经在uwp app中找到了,您可以使用添加ArcSegment代替 .UWP应用程序有自己的绘制API,它可能没有与Windows窗体中的方法名称和参数相同的方法 . 但是你应该能够在uwp中使用其他方法来实现相同的效果 . 例如,AddArc方法有三个参数,
Rectangle
用于定义x直径和y直径以及形状位置,startAngle
和sweepAngle
用于定义开始和结束角度 . 在uwp app中,ArcSegment
可以通过size
属性定义弧x半径和y半径,并指定定义开始和结束位置 .例如,在windows窗体中,我们可以使用以下代码绘制弧形;
在uwp应用程序中,您可以通过以下代码在xaml中执行相同的操作:
或代码背后:
结果如下:
总而言之,您应该能够找到API来绘制您在表单中完成的相同操作 .