C# (复合)c语言中的几何混乱#

C# (复合)c语言中的几何混乱#,c#,wpf,inkcanvas,C#,Wpf,Inkcanvas,我试图在InkCanvas上创建一个复杂的复合形状,但我一定是做错了什么,因为我所期望的不是。我试过几种不同的方法来实现这一点 所以我有这个方法 private void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e) { Stroke stroke = e.Stroke; // Close the "shape". Sty

我试图在InkCanvas上创建一个复杂的复合形状,但我一定是做错了什么,因为我所期望的不是。我试过几种不同的方法来实现这一点

所以我有这个方法

    private void InkCanvas_StrokeCollected(object sender, InkCanvasStrokeCollectedEventArgs e)
    {
        Stroke stroke = e.Stroke;

        // Close the "shape".
        StylusPoint firstPoint = stroke.StylusPoints[0];
        stroke.StylusPoints.Add(new StylusPoint() { X = firstPoint.X, Y = firstPoint.Y });

        // Hide the drawn shape on the InkCanvas.
        stroke.DrawingAttributes.Height = DrawingAttributes.MinHeight;
        stroke.DrawingAttributes.Width = DrawingAttributes.MinWidth;

        // Add to GeometryGroup. According to http://msdn.microsoft.com/en-us/library/system.windows.media.combinedgeometry.aspx
        // a GeometryGroup should work better at Unions.
        _revealShapes.Children.Add(stroke.GetGeometry());

        Path p = new Path();
        p.Stroke = Brushes.Green;
        p.StrokeThickness = 1;
        p.Fill = Brushes.Yellow;
        p.Data = _revealShapes.GetOutlinedPathGeometry();

        selectionInkCanvas.Children.Clear();        
        selectionInkCanvas.Children.Add(p);
    }
但我得到的是:

那么我错在哪里呢

蒂亚,
Ed

问题在于笔划返回的几何体。GetGeometry()是笔划周围的路径,因此用黄色填充的区域正好位于笔划的中间。如果将线条加粗,您可以更清楚地看到这一点:

_revealShapes.Children.Add(stroke.GetGeometry(new DrawingAttributes() { Width = 10, Height = 10 }));
如果您自己将手写笔点列表转换为StreamGeometry,则可以执行所需操作:

var geometry = new StreamGeometry();
using (var geometryContext = geometry.Open())
{
    var lastPoint = stroke.StylusPoints.Last();
    geometryContext.BeginFigure(new Point(lastPoint.X, lastPoint.Y), true, true);
    foreach (var point in stroke.StylusPoints)
    {
        geometryContext.LineTo(new Point(point.X, point.Y), true, true);
    }
}
geometry.Freeze();
_revealShapes.Children.Add(geometry);

你想要达到什么?在我看来,会发生的是:好的,谢谢!这就是啊哈!马上。。笔划几何图形是围绕笔划的路径。这一切现在都有意义了,而且也有效!再次感谢!