我正在使用Xamarin表单制作应用程序 .
我想用SKPath绘制一条平滑的路径(样条曲线),但我无法找到一种简单的方法来实现这一点 .
Skiasharp目前不支持它,除非我自己顺利完成路径 .
谢谢 .
SkiaSharp支持三次贝塞尔曲线 . 因此,您可以做的是将样条线划分为多个线段(点确定线段 endpoints ),并使用三次贝塞尔曲线绘制每个线段 . 为此,您需要在样条曲线中的每个点之间引入两个控制点 . 需要选择这些点,以使相邻段中的曲线平滑连接 .
我刚刚做了一个这样的实现 . public static SKPath CreateSpline(params SKPoint[] Points) 方法生成一个路径,您可以使用该路径在点之间绘制样条线 . 您可以在此处查看实施:
public static SKPath CreateSpline(params SKPoint[] Points)
https://github.com/PeterWaher/IoTGateway/blob/master/Script/Waher.Script.Graphs/Functions/Plots/Plot2DCurve.cs
例:
我不确定你究竟在问什么,但有两个平滑区域:
使用 SKPaint.IsAntialias 进行消除锯齿:
SKPaint.IsAntialias
var paint = new SKPaint { IsAntialias = true }; canvas.DrawPath (path, paint);
路径曲线:
如果需要路径中的曲线(例如圆角),则需要使用各种曲线方法 . 这些包括但不限于 SKPath.ArcTo() 和 'SKPath.CubicTo() :
SKPath.ArcTo()
'SKPath.CubicTo()
var path = new SKPath(); path.MoveTo(10, 10); path.ArcTo(SKRect.Create(10, 10, 30, 30), 0, 45);
路径文档:https://developer.xamarin.com/api/type/SkiaSharp.SKPath/
2 回答
SkiaSharp支持三次贝塞尔曲线 . 因此,您可以做的是将样条线划分为多个线段(点确定线段 endpoints ),并使用三次贝塞尔曲线绘制每个线段 . 为此,您需要在样条曲线中的每个点之间引入两个控制点 . 需要选择这些点,以使相邻段中的曲线平滑连接 .
我刚刚做了一个这样的实现 .
public static SKPath CreateSpline(params SKPoint[] Points)
方法生成一个路径,您可以使用该路径在点之间绘制样条线 . 您可以在此处查看实施:https://github.com/PeterWaher/IoTGateway/blob/master/Script/Waher.Script.Graphs/Functions/Plots/Plot2DCurve.cs
例:
我不确定你究竟在问什么,但有两个平滑区域:
使用
SKPaint.IsAntialias
进行消除锯齿:路径曲线:
如果需要路径中的曲线(例如圆角),则需要使用各种曲线方法 . 这些包括但不限于
SKPath.ArcTo()
和'SKPath.CubicTo()
:路径文档:https://developer.xamarin.com/api/type/SkiaSharp.SKPath/