Question

Je suis en train de créer une forme composite complexe sur un InkCanvas, mais je dois faire quelque chose de mal, comme ce que je comptais arriver, n'est pas. J'ai essayé plusieurs incarnations différentes d'y parvenir.

J'ai donc cette méthode.

    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);
    }

Mais ce que je reçois: http://img72.imageshack.us/img72/1286/actual.png

Alors, où vais-je tort?

TIA, Ed

Était-ce utile?

La solution

Le problème est que la géométrie retournée par stroke.GetGeometry () est un chemin autour de la course, de sorte que la zone que vous remplissons avec le jaune est juste au milieu de la course. Vous pouvez voir plus clairement si vous faites les lignes plus épaisses:

_revealShapes.Children.Add(stroke.GetGeometry(new DrawingAttributes() { Width = 10, Height = 10 }));

Vous pouvez faire ce que vous voulez si vous convertissez la liste des points de stylet à un StreamGeometry vous:

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);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top