Eraser in SKCanvas

Hi, Please let us know the way to integrate Eraser in SKCanvas. We are drawing using SKPaint, But we need to integrate Eraser with some stoke width.

Regards

Posts

  • mattleibowmattleibow Xamurai ZAXamarin Team Xamurai
    edited June 2017

    This can be done by setting the paint's BlendMode:

    // create a bitmap that is solid blue (represents our canvas that we want to erase)
    var bitmap = new SKBitmap(256, 256);
    bitmap.Erase(SKColors.Blue);
    
    // now "erase" a section, making a "hole"
    using (var canvas = new SKCanvas(bitmap))
    using (var paint = new SKPaint())
    {
        paint.IsAntialias = true;
        paint.Color = SKColors.Transparent;
        paint.BlendMode = SKBlendMode.Src;
    
        canvas.DrawCircle(100, 100, 80, paint);
    }
    

    The bitmap will now have a "hole" in it. In the same way, you can just erase any surface by setting the BlendMode to be SKBlendMode.Src. This just takes the properties of the paint, and forces a replace of the pixels:

    https://developer.xamarin.com/api/type/SkiaSharp.SKBlendMode/#F:SkiaSharp.SKBlendMode.Src

    Only the source will be present. [Porter Duff Compositing Operators]

  • AmitsainiAmitsaini INMember

    Thanks Matthew.

    I have tried with above and able to integrate the Eraser.

    Regards
    Amit

  • mattleibowmattleibow Xamurai ZAXamarin Team Xamurai

    Awesome!

  • rkshrnairrkshrnair Member
    edited July 2018

    Good

Sign In or Register to comment.