Getting ink recognition working in WPF


Been a while since i have done any inking code and since Windows Vista makes these type of applications possible without the need for a tablet pc i decided to take a look at how to create these applications with Windows Presentation Foundation. 

Turns out you only need three lines of code with an inkcanvas to make this work!!

Dim myAnalyzer As New InkAnalyzer()

myAnalyzer.AddStrokes(InkCanvas1.Strokes)

Dim status As AnalysisStatus = myAnalyzer.Analyze()

Button1.Content = myAnalyzer.GetRecognizedString()

Unfortunately by default this code won’t work as the System.Windows.Ink namespace doesn’t implement the InkAnalyzer object.  You have to add a reference to the assembly IAWinFX.dll

This assembly is located at:

c:\Program Files\Reference Assemblies\Microsoft\Tablet PC\v1.7\IAWinFX.dll

-I won’t say how long this took to find out!  i have included both the XAML and code below for a simple inking application with recognition.

image

 

<Window x:Class=”Window1″
    xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
    xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
    Title=”Window1″ Height=”300″ Width=”300″>
    <Grid>
    <InkCanvas Margin=”0,55,0,0″ Name=”InkCanvas1″ Background=”Blue” />
    <Button Height=”23″ Margin=”15.5,13,0,0″ Name=”Button1″ Width=”75″ VerticalAlignment=”Top”>Button</Button>
  </Grid>
</Window>

 

And the code Behind….

 

Imports System.Windows.Ink

Class Window1

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim myAnalyzer As New InkAnalyzer()
        myAnalyzer.AddStrokes(InkCanvas1.Strokes)
        Dim status As AnalysisStatus = myAnalyzer.Analyze()
        Button1.Content = myAnalyzer.GetRecognizedString()

    End Sub
End Class

 

Oh yeah this post is being published by the beta2 of Windows Live Writer Beta2

http://windowslivewriter.spaces.live.com/blog/cns!D85741BB5E0BE8AA!1272.entry


Comments (4)

  1. All style tags after the first 30 style tags on an HTML page are not applied in Internet Explorer workaround…

  2. I was talking to Ric at Wacom and i mentioned the WPF training I was helping with and he asked if we

  3. I have had a couple people mention my inking code not working on non tablet PC despite having a Wacom

  4. I have had a couple people mention my inking code not working on non tablet PC despite having a Wacom