Exemplo n.º 1
0
        public static void EraseLine(this CanvasRenderTarget target, Vector2 from, Vector2 to,
                                     float strokeWidth, CanvasStrokeStyle strokeStyle)
        {
            var rect = new Rect(0, 0, target.SizeInPixels.Width, target.SizeInPixels.Height);

            using (var overall = CanvasGeometry.CreateRectangle(target.Device, rect))
                using (var path = new CanvasPathBuilderHelper(from, to).Build(target.Device))
                    using (var eraserbase = CanvasGeometry.CreatePath(path))
                        using (var eraser = eraserbase.Stroke(strokeWidth, strokeStyle))
                            using (var mask = overall.CombineWith(eraser, Matrix3x2Identity, CanvasGeometryCombine.Exclude))
                                using (var buffer = target.Clone())
                                {
                                    using (var bds = buffer.CreateDrawingSession())
                                    {
                                        bds.Clear();
                                        using (bds.CreateLayer(1.0f, mask))
                                        {
                                            bds.DrawImage(target);
                                        }
                                    }
                                    using (var ds = target.CreateDrawingSession())
                                    {
                                        ds.Clear();
                                        ds.DrawImage(buffer);
                                    }
                                }
        }
Exemplo n.º 2
0
 public static void EraseLine(this CanvasRenderTarget target, Vector2 from, Vector2 to,
     float strokeWidth, CanvasStrokeStyle strokeStyle)
 {
     var rect = new Rect(0, 0, target.SizeInPixels.Width, target.SizeInPixels.Height);
     using (var overall = CanvasGeometry.CreateRectangle(target.Device, rect))
     using (var path = new CanvasPathBuilderHelper(from, to).Build(target.Device))
     using (var eraserbase = CanvasGeometry.CreatePath(path))
     using (var eraser = eraserbase.Stroke(strokeWidth, strokeStyle))
     using (var mask = overall.CombineWith(eraser, Matrix3x2Identity, CanvasGeometryCombine.Exclude))
     using (var buffer = target.Clone())
     {
         using (var bds = buffer.CreateDrawingSession())
         {
             bds.Clear();
             using (bds.CreateLayer(1.0f, mask))
             {
                 bds.DrawImage(target);
             }
         }
         using (var ds = target.CreateDrawingSession())
         {
             ds.Clear();
             ds.DrawImage(buffer);
         }
     }
 }