locked
Eraser in SKCanvas RRS feed

  • Question

  • User327975 posted

    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

    Friday, June 2, 2017 10:46 AM

All replies

  • User68536 posted

    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]

    Monday, June 5, 2017 10:08 PM
  • User327975 posted

    Thanks Matthew.

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

    Regards Amit

    Tuesday, June 13, 2017 11:04 AM
  • User68536 posted

    Awesome!

    Thursday, June 15, 2017 11:03 AM
  • User370620 posted

    Good

    Monday, July 9, 2018 3:08 PM