Pregunta

Estoy intentando crear 1 forma compleja compuesta de un InkCanvas, pero debo estar haciendo algo mal, ya que lo que estaba esperando a suceder, no lo es. He intentado varias encarnaciones diferentes de conseguir esto.

Así que tengo este método.

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

Pero esto es lo que me sale: http://img72.imageshack.us/img72/1286/actual.png

Entonces, ¿dónde estoy haciendo mal?

TIA, Ed

¿Fue útil?

Solución

El problema es que la geometría devuelto por stroke.GetGeometry () es un camino alrededor de la carrera, por lo que el área que está llenado con el amarillo es sólo la mitad de la carrera. Esto se puede ver con mayor claridad si haces las líneas más gruesas:

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

Se puede hacer lo que quiera si convierte la lista de puntos de la aguja a un StreamGeometry mismo:

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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top