Skiasharp: Can't remove clipping mask.

Created on 24 Jan 2017  路  2Comments  路  Source: mono/SkiaSharp

SkiaSharp ver : 1.56.0
tested on Xamarin.Forms

hi,

Once I clip canvas, like below
canvas.ClipPath(mypath);

There is no way to remove clipping path like,

  1. canvas.ClipPath(null); - error because path can not be null.
  2. doing canvas.ClipPath(newfullscreenpath); - not working.

I really need to remove clipping mask.
If it's not working, I have to create new SKCanvasView and put on it to archive what I want.
(Like a Photoshop Layer.)
I tried it but performance is bad.

Most helpful comment

I haven't tested it yet, but have you tried saving the canvas, then restoring it after the clipped drawing operation:

canvas.Save();
canvas.ClipPath(mypath);
// .. do stuff ...
canvas.Restore();

You can also make use of the nice SKAutoCanvasRestore:

using (new SKAutoCanvasRestore(canvas)) {
    canvas.ClipPath(mypath);
    // .. do stuff ...
}

According to the docs: https://developer.xamarin.com/api/member/SkiaSharp.SKCanvas.Save()/

This call saves the current matrix, clip, and draw filter, and pushes a copy onto a private stack. Subsequent calls to translate, scale, rotate, skew, concat or clipping path or drawing filter all operate on this copy. When the balancing call to聽SKCanvas.Restore聽is made, the previous matrix, clipping, and drawing filters are restored.

All 2 comments

I haven't tested it yet, but have you tried saving the canvas, then restoring it after the clipped drawing operation:

canvas.Save();
canvas.ClipPath(mypath);
// .. do stuff ...
canvas.Restore();

You can also make use of the nice SKAutoCanvasRestore:

using (new SKAutoCanvasRestore(canvas)) {
    canvas.ClipPath(mypath);
    // .. do stuff ...
}

According to the docs: https://developer.xamarin.com/api/member/SkiaSharp.SKCanvas.Save()/

This call saves the current matrix, clip, and draw filter, and pushes a copy onto a private stack. Subsequent calls to translate, scale, rotate, skew, concat or clipping path or drawing filter all operate on this copy. When the balancing call to聽SKCanvas.Restore聽is made, the previous matrix, clipping, and drawing filters are restored.

Yey!!
Your solution is working.
Thanks.

Was this page helpful?
0 / 5 - 0 ratings