以下是Android代碼。如何平滑WPF線段的路徑圖
path.moveTo(xx, yy);
for (...) {
path.lineTo(xx, yy);
}
canvas.drawPath(this.path, paint);
爲了去除尖角,我使用
final CornerPathEffect cornerPathEffect = new CornerPathEffect(50);
paint.setPathEffect(cornerPathEffect);
當談到WPF,我使用下面的代碼。
PathFigure pathFigure = new PathFigure();
pathFigure.StartPoint = new Point(xx, yy);
for (...) {
LineSegment lineSegment = new LineSegment(new Point(xx, yy), true);
lineSegment.IsSmoothJoin = true;
pathFigure.Segments.Add(lineSegment);
}
PathGeometry pathGeometry = new PathGeometry(new PathFigure[] { pathFigure });
drawingContext.DrawGeometry(null, new Pen(Brushes.White, 3), pathGeometry);
我收到以下效果。
需要注意的是,我使用PolyQuadraticBezierSegment
或PolyBezierSegment
避免。它傾向於變成不穩定。這意味着,無論何時將新的入點添加到折線圖中,新添加的點都會改變已經在屏幕上繪製的舊路徑。作爲最終效果,你可能觀察到整個線條圖是搖晃
我可以知道在WPF中,我可以如何平滑線段?雖然我用過lineSegment.IsSmoothJoin = true;
,但我仍然可以看到尖銳的角落。我可以擁有相當於Android的CornerPathEffect的東西嗎?