Esempio 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);
         }
     }
 }
Esempio n. 2
0
 public static void DrawLine(this CanvasRenderTarget target, Vector2 from, Vector2 to, Color color,
     float strokeWidth, CanvasStrokeStyle strokeStyle, float opacity)
 {
     using (var ds = target.CreateDrawingSession())
     {
         ds.DrawLine(from, to, new Color() { A = (byte)(255 * opacity), B = color.B, G = color.G, R = color.R },
             strokeWidth, strokeStyle);
     }
 }