Xamarin使用Skia Sharp形成点缀Cirlce

时间:2019-07-08 12:04:14

标签: xamarin xamarin.forms skiasharp skia

我们如何使用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);

1 个答案:

答案 0 :(得分:0)

您非常接近。您只需要了解自己在做什么。您是否正确设置页面的构造方法?您必须

  1. 创建一个SKCanvasView实例并将其添加到页面的内容中。
  2. 因此,假设您的类或页面的名称为SimpleCirclePage.cs,则需要将其与其他项一起添加到其中。
  3. 将事件处理程序添加到SKCanvasView实例的PaintSurface事件中。

构造函数

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);
}