Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

How to cut a part of SKPath in SkiaSharp (Xamarin.Forms)?

kin4kin4 Member

Hello!
I have an SKPath that is moving using SKPath.Offset Method and I need to cut a part of a path that is already out of the screen. I would appreciate any help.

void view1_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
    {
        var surface = e.Surface;
        var canvas = surface.Canvas;

        canvas.Clear(SKColors.Black);
        x = canvas.LocalClipBounds.Right;
        y = offset - someValueFromDatabase;
        path.LineTo(new SKPoint(x, y));
        path.Offset(-10f,0);

        canvas.DrawPath(path, paint);
    }

Answers

  • LandLuLandLu Member, Xamarin Team Xamurai

    Why do you want to draw a path outside of the canvas?
    We could add some statements to avoid that like:

    if (x > info.Width) x = info.Width;
    if (x < 0) x = 0;
    if (y > info.Height) y = info.Height;
    if (y < 0) y = 0;
    path.LineTo(new SKPoint(x, y));
    path.Offset(-10f, 0);
    
  • kin4kin4 Member

    @LandLu said:
    Why do you want to draw a path outside of the canvas?
    We could add some statements to avoid that like:

    if (x > info.Width) x = info.Width;
    if (x < 0) x = 0;
    if (y > info.Height) y = info.Height;
    if (y < 0) y = 0;
    path.LineTo(new SKPoint(x, y));
    path.Offset(-10f, 0);
    

    if (x < 0) x = 0; that doesn't work, because new points are drawn on the right edge of the screen so x is always
    x = canvas.LocalClipBounds.Right; the width of the path is increasing and so when I move this entire path it moves slower and slower.

Sign In or Register to comment.