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

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

问题描述

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

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

Skiasharp 目前不支持它,除非我自己使路径顺利.

谢谢.

解决方案

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

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

I'm making app with using Xamarin forms.

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

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

Thanks.

解决方案

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.

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

Example:

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

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