WPF将Point数组转换为PathGeometry
Posted 棉晗榜
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF将Point数组转换为PathGeometry相关的知识,希望对你有一定的参考价值。
xaml页面代码,用的画布,用鼠标画线,然后记录画的Point点
<Canvas x:Name="can01" Background="LightGreen" MouseMove="Canvas_MouseMove" ></Canvas>
/// <summary>
/// 鼠标画线轨迹
/// </summary>
static List<Point> points = new List<Point>();
private void Canvas_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
Line line = new Line();
line.Name = "guiji02";
line.X1 = startPoint.X;
line.Y1 = startPoint.Y;
line.X2 = e.GetPosition(this.can01).X;
line.Y2 = e.GetPosition(this.can01).Y;
line.Stroke = Brushes.Black;
lineList.Add(line);
this.can01.Children.Add(line);
startPoint = e.GetPosition(this.can01);
记录路径点
points.Add(startPoint);
}
}
//将Point点集合转换为PathGeometry
if (points.Count == 0)
{
return;
}
//鼠标绘制的路径
List<LineSegment> segments = new List<LineSegment>();
foreach (var item in points)
{
segments.Add(new LineSegment(item, true));
}
PathFigure figure = new PathFigure(points.First(), segments, false);
PathGeometry myPathGeometry = new PathGeometry();
myPathGeometry.Figures.Add(figure);
//这个myPathGeometry可用于动画移动路径
以上是关于WPF将Point数组转换为PathGeometry的主要内容,如果未能解决你的问题,请参考以下文章
如何将String []转换为TouchAction命令的Point