Hi:
this is the code of recoginition of form in class cs
private readonly Canvas _reconigtionCanvas;
private readonly InkCanvas _inkCanvas;
InkAnalyzer inkAnalyzer = new InkAnalyzer();
IReadOnlyList inkStrokes = null;
InkAnalysisResult inkAnalysisResults = null;
public InkRecognitionService(Canvas reconigtionCanvas, InkCanvas inkCanvas)
{
_reconigtionCanvas = reconigtionCanvas;
_inkCanvas = inkCanvas;
}
public void DrawEllipse(InkAnalysisInkDrawing shape)
{
var points = shape.Points;
Ellipse ellipse = new Ellipse();
ellipse.Width = shape.BoundingRect.Width;
ellipse.Width = shape.BoundingRect.Height;
Canvas.SetTop(ellipse, shape.BoundingRect.Top);
Canvas.SetLeft(ellipse, shape.BoundingRect.Left);
var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));
ellipse.Stroke = brush;
ellipse.StrokeThickness = 2;
_reconigtionCanvas.Children.Add(ellipse);
}
///
///
///
///
public void DrawPolygon(InkAnalysisInkDrawing shape)
{
List points = new List(shape.Points);
Polygon polygon = new Polygon();
foreach (Point point in points)
{
polygon.Points.Add(point);
}
var brush = new SolidColorBrush(Windows.UI.ColorHelper.FromArgb(255, 0, 0, 255));
polygon.Stroke = brush;
polygon.StrokeThickness = 2;
_reconigtionCanvas.Children.Add(polygon);
}
public async Task RecognizeStrokes()
{
inkStrokes = _inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
if (inkStrokes.Count > 0)
{
inkAnalyzer.AddDataForStrokes(inkStrokes);
inkAnalysisResults = await inkAnalyzer.AnalyzeAsync();
if (inkAnalysisResults.Status == InkAnalysisStatus.Updated)
{
var inkwordNodes =
inkAnalyzer.AnalysisRoot.FindNodes(
InkAnalysisNodeKind.InkWord);
foreach (InkAnalysisInkWord node in inkwordNodes)
{
foreach (var strokeId in node.GetStrokeIds())
{
var stroke = _inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(strokeId);
stroke.Selected = true;
}
inkAnalyzer.RemoveDataForStrokes(node.GetStrokeIds());
}
_inkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
var inkdrawingNodes =
inkAnalyzer.AnalysisRoot.FindNodes(
InkAnalysisNodeKind.InkDrawing);
foreach (InkAnalysisInkDrawing node in inkdrawingNodes)
{
if (node.DrawingKind == InkAnalysisDrawingKind.Drawing)
{
// Catch and process unsupported shapes.
}
else
{
if (node.DrawingKind == InkAnalysisDrawingKind.Circle ||
node.DrawingKind == InkAnalysisDrawingKind.Ellipse )
{
DrawEllipse(node);
}
else
{
DrawPolygon(node);
}
foreach (var strokeId in node.GetStrokeIds())
{
var stroke = _inkCanvas.InkPresenter.StrokeContainer.GetStrokeById(strokeId);
stroke.Selected = true;
}
}
inkAnalyzer.RemoveDataForStrokes(node.GetStrokeIds());
}
_inkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
}
}
}
}
}