gpt4 book ai didi

xamarin - SkiaSharp ArcTo方法不绘制曲线

转载 作者:行者123 更新时间:2023-12-02 03:51:25 25 4
gpt4 key购买 nike

我正在尝试使用以下代码在 SkiaSharp Canvas View 上绘制圆弧。

path3.ArcTo(new SKPoint(0, h/2), 1.57f, SKPathArcSize.Large,
SKPathDirection.Clockwise, new SKPoint(w/2, h));

但它绘制的不是曲线,而是直线。如何将其做成曲线?

完整代码

 private void OnPainting(object sender, SKPaintSurfaceEventArgs e)
{

var surface = e.Surface;
var canvas = surface.Canvas;
canvas.Clear(SKColors.White);

var w = e.Info.Width;
var h = e.Info.Height;

var pathStroke3 = new SKPaint
{
IsAntialias = true,
Style = SKPaintStyle.StrokeAndFill,
Color = new SKColor(240, 0, 100, 250),
StrokeWidth = 5
};

var path3 = new SKPath { FillType = SKPathFillType.EvenOdd };
path3.MoveTo(0, h/2);
path3.ArcTo(new SKPoint(0, h/2), 1.57f, SKPathArcSize.Large, SKPathDirection.Clockwise, new SKPoint(w/2, h));
path3.LineTo(0, h);
path3.Close();
canvas.DrawPath(path3, pathStroke3);


}

XAML

 <Grid x:Name="controlGrid" ColumnSpacing="0" RowSpacing="0" Padding="0" BackgroundColor="White" >
<Grid.RowDefinitions>
<RowDefinition Height="4*" />
<RowDefinition Height="6*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<views:SKCanvasView PaintSurface="OnPainting" EnableTouchEvents="True"
Touch="OnTouch" HeightRequest="300" Grid.Row="0"/>
</Grid>

enter image description here

最佳答案

您的 x 半径为零,因此 ArcTo 会向从当前点到退出点的路径添加一条线。

arcTo appends Line to xy if either radii are zero, or if last Path Point equals (x, y). arcTo scales radii r to fit last Path Point and xy if both are greater than zero but too small.

你可以这样做:

path3.ArcTo(new SKPoint(100, 100), 0, SKPathArcSize.Large, SKPathDirection.Clockwise, new SKPoint(w / 2, h));

enter image description here

但我不知道你的绘画意图是什么;凹、凸、有界、无界等...但使用 ConicTo 的其他一些示例可能更接近我认为您的意图:

path3.ConicTo(w / 3, h / 2, w / 2, h, 0.50f);

enter image description here

path3.ConicTo(0, h - (h / 5), w / 2, h, 0.50f);

enter image description here

您可能需要查看官方文档以了解 ArcTo 如何解析为弧线、圆锥曲线和移动:

关于xamarin - SkiaSharp ArcTo方法不绘制曲线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45318279/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com