我们如何使用Skia Sharp创建一个以Xamarin形式创建一个虚线的圆圈,我尝试了很多,但是我无法实现它可以帮助我。
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = Color.Red.ToSKColor(),
StrokeWidth = 10
};
canvas.DrawCircle(info.Width / 3, info.Height / 2, 100, paint);
您非常接近。您只需要了解自己在做什么。您是否正确设置页面的构造函数?你必须
- 创建一个SkCanvasView的实例,然后将其添加到页面内容中。
- 因此,假设您的班级或页面的名称是SimpleCirclePage.cs,您需要将其与其他项目一起添加。
- 将事件处理程序添加到您的skcanvasview实例的油漆脸部事件中。
构造函数
public SimpleCirclePage()
{
SKCanvasView canvasView = new SKCanvasView();
canvasView.PaintSurface += OnCanvasViewPaintSurface;
Content = canvasView;
}
活动处理程序
void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
{
SKImageInfo info = args.Info;
SKSurface surface = args.Surface;
SKCanvas canvas = surface.Canvas;
canvas.Clear();
// Creating the Outline of the circle with Black
SKPaint paint = new SKPaint
{
Style = SKPaintStyle.Stroke,
Color = Color.Black.ToSKColor(),
StrokeWidth = 22
};
canvas.DrawCircle(info.Width / 2, info.Height / 2, 100, paint);
// Filling the circle with red
paint.Style = SKPaintStyle.Fill;
paint.Color = SKColors.Red;
canvas.DrawCircle(info.Width / 2, info.Height / 2, 100, paint);
}