在Xamarin.Forms上使用SkiaSharp lib绘制样条曲线(平滑路径)? [英] Draw spline(smooth path) with SkiaSharp lib on Xamarin.Forms?

查看:326
本文介绍了在Xamarin.Forms上使用SkiaSharp lib绘制样条曲线(平滑路径)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin表单制作应用程序.

I'm making app with using Xamarin forms.

我想使用SKPath绘制一条平滑的路径(样条线),但是我找不到一种简单的方法来实现此目的.

I want to draw a smooth path (spline) with SKPath, but I am unable to find a simple way to achieve this.

除非我自己做得顺利,否则Skiasharp当前不支持它.

Skiasharp does not support it currently unless I make path smoothly myself.

谢谢.

推荐答案

SkiaSharp支持三次贝塞尔曲线.因此,您可以做的是,将样条曲线划分为多个段(点确定段端点),然后使用三次贝塞尔曲线绘制每个段.为此,您需要在样条曲线的每个点之间引入两个控制点.需要选择这些点,以使相邻线段中的曲线平滑连接.

SkiaSharp supports cubic Bezier curves. So, what you can do, is divide the spline into segments (points determine segment endpoints), and draw each segment using a cubic Bezier curve. To do this, you need to introduce two control points between each point in your spline curve. These points need to be selected so that the curves in neighboring segments connect smoothly.

我只是实现了这一点. public static SKPath CreateSpline(params SKPoint[] Points)方法生成一条路径,可用于在点之间绘制样条线.您可以在此处查看实现:

I just did an implementation of this. The public static SKPath CreateSpline(params SKPoint[] Points) method generates a path that you can use to draw a spline between points. You can view the implementation here:

https://github.com/PeterWaher/IoTGateway/blob/master/Script/Waher.Script.Graphs/Functions/Plots/Plot2DCurve.cs

示例:

这篇关于在Xamarin.Forms上使用SkiaSharp lib绘制样条曲线(平滑路径)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆