質問
私はインクカンバスに1つの複雑な複合形状を作成しようとしていますが、私は何か間違ったことをしているに違いありません。私はこれを達成するためのいくつかの異なる化身を試しました。
だから私はこの方法を持っています。
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);
}
しかし、これは私が得るものです:http://img72.imageshack.us/img72/1286/actual.png
それで、私はどこに間違っているのでしょうか?
ティア、編
解決
問題は、stroke.getgeometry()によって返されるジオメトリがストローク周辺の経路であるため、黄色で詰め込んでいる領域はストロークの真ん中にあることです。線を厚くすると、これをより明確に見ることができます。
_revealShapes.Children.Add(stroke.GetGeometry(new DrawingAttributes() { Width = 10, Height = 10 }));
スタイラスポイントのリストを自分でストリームジオメトリに変換した場合、必要なことをすることができます。
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);
所属していません StackOverflow