|
// Basic Shape Recognition Application
// using the InkAnalysis API, part of the
// Tablet PC Platform SDK 1.75 Input Supplement
// Gavin Gear
// 01/2007
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Ink;
namespace ShapeReco
{
public partial class Form1 : Form
{
private InkOverlay overlay_;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.overlay_ = new InkOverlay(this);
this.overlay_.Enabled = true;
}
private void buttonRecoShapes_Click(object sender, EventArgs e)
{
// Create a new InkAnalyzer referencing the strokes from
// our InkOverlay's Ink object, and synchronized to the main Form
InkAnalyzer analyzer = new InkAnalyzer(this.overlay_.Ink, this);
analyzer.AddStrokes(this.overlay_.Ink.Strokes);
if (this.overlay_.Ink.Strokes.Count > 0)
{
analyzer.AddStrokes(this.overlay_.Ink.Strokes);
}
AnalysisStatus status = analyzer.Analyze();
if (status.Successful == true)
{
ContextNodeCollection DrawingNodes = analyzer.FindNodesOfType(ContextNodeType.InkDrawing);
string shapeString = "Shapes Found:" + Environment.NewLine;
foreach (InkDrawingNode node in DrawingNodes)
{
shapeString += node.GetShapeName() + Environment.NewLine;
}
MessageBox.Show(shapeString, "Recognized Shapes");
}
else
{
MessageBox.Show("Analysis failed, exiting");
Application.Exit();
}
}
}
} |