2010-06-21 5 views
1

InkCanvas에서 복잡한 복합 모양 1 개를 만들려고하는데, 내가 예상했던대로 잘못된 것을해야합니다. 그렇지 않습니다. 나는 이것을 달성하기 위해 여러 가지 다른 화신을 시도했다.(Composite) C#의 기하학 혼란

그래서이 방법이 있습니다. http://img72.imageshack.us/img72/1286/actual.png

을 어디 내가 잘못 갈거야 :

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

는 그러나 이것은 내가 무엇을 얻을?

TIA, 에드

+1

당신이 무엇을 원하는가 이루다?? –

+0

무엇이 내 마음 속에서 일어날 것입니까? http://img685.imageshack.us/img685/6761/expected.png –

답변

2

문제는 stroke.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); 
+0

감사합니다! 그것은 AHA입니다! 바로 그 순간 .. 뇌졸중 기하학은 뇌졸중 주위의 경로입니다. 이제는 모두 의미가 있으며 작동합니다! 다시 한 번 감사드립니다! –