set drawing limits

I'm using SkiaSharp to draw inside an image.
But I would like it to be drawn only within the outline of the horse, if the user tries to take a risk outside that area of ​​the horse for example, there is no risk of the outline.
Could someone give me a hint how to do this?

Answers

  • LeonLuLeonLu Member, Xamarin Team Xamurai

    You can enable the TouchEvents for your SKCanvasView, then add the touche event.

     <forms:SKCanvasView x:Name="SkCanvasView" 
        EnableTouchEvents="True" 
        Touch="SkCanvasView_Touch"
        PaintSurface="SkCanvasView_OnPaintSurface" />
    

    Then you can subscribte to it and handle the it.

     private void SkCanvasView_Touch(
      object sender, SKTouchEventArgs e)
     {
    if (e.ActionType == 
        SkiaSharp.Views.Forms.SKTouchAction.Pressed)
    {
        _lastTouchPoint = e.Location;
        e.Handled = true;
    }
    
    _lastTouchPoint = e.Location;
    
    // update the Canvas as you wish
    SkCanvasView.InvalidateSurface();
      }
    

    According to the location, then you can judge the border. then update your canvans.

    There is a blog about it.

    https://theconfuzedsourcecode.wordpress.com/2017/08/20/so-i-gave-a-tech-talk-on-skiasharp-with-xamarin-forms/

Sign In or Register to comment.