Welcome to MSDN Blogs Sign in | Join | Help

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

Published Thursday, May 31, 2007 9:45 PM by Charles_Sterling

Comments

Friday, June 01, 2007 12:42 AM by Christopher Steen

# Link Listing - May 31, 2007

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

Tuesday, June 19, 2007 9:37 PM by Ozzie Rules Blogging

# Wacom to give away a free Bamboo Tablet at the WPF Day.

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

Thursday, July 05, 2007 6:43 AM by Ozzie Rules Blogging

# Managed Inking Code on non Tablet PC's

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

Thursday, July 05, 2007 7:18 AM by Noticias externas

# Managed Inking Code on non Tablet PC's

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

New Comments to this post are disabled
 
Page view tracker