例如,讓 user 框選照片中的大頭,裁切下來,並加以應用。
因此,在 runtime 建立一組 path,
並隨著 user 的 click 新增 node,
是一項重要的流程。
以下是我利用 path 畫出一個正方形的範例,
並以 canvas 為其父物件。為了讓範例簡化,
click、clip、image 等部分的處理,並沒有加入範例中。
Path path = new Path(); PathGeometry pathGeometry = new PathGeometry(); path.Data = pathGeometry; pathGeometry.Figures = new PathFigureCollection(); PathFigure figur = new PathFigure(); pathGeometry.Figures.Add(figur); figur.StartPoint = new Point(0, 0); LineSegment seg1 = new LineSegment(); seg1.Point = new Point(100, 0); figur.Segments.Add(seg1); LineSegment seg2 = new LineSegment(); seg2.Point = new Point(100, 100); figur.Segments.Add(seg2); LineSegment seg3 = new LineSegment(); seg3.Point = new Point(0, 100); figur.Segments.Add(seg3); path.Fill = new SolidColorBrush(Colors.Blue); Canvas.SetTop(path, 200); Canvas.SetLeft(path, 300); Canvas canvas = new Canvas(); canvas.Background = new SolidColorBrush(Colors.DarkGray); canvas.Width = 50; canvas.Height = 50; canvas.HorizontalAlignment = HorizontalAlignment.Left; canvas.VerticalAlignment = VerticalAlignment.Top; canvas.Children.Add(path); this.LayoutRoot.Children.Add(canvas);[refernece]
How to draw a path at runtime
沒有留言:
張貼留言