Storing Ink

The Save methods provide support for storing ink as Ink Serialized Format (ISF). Constructors for the StrokeCollection class provide support for reading ink data.

Ink Storage and Retrieval

This section discusses how to store and retrieve ink in the WPF platform.

The following example implements a button-click event handler that presents the user with a File Save dialog box and saves the ink from an InkCanvas out to a file.

private void buttonSaveAsClick(object sender, RoutedEventArgs e)
{
    SaveFileDialog saveFileDialog1 = new SaveFileDialog();
    saveFileDialog1.Filter = "isf files (*.isf)|*.isf";

    if (saveFileDialog1.ShowDialog() == true)
    {
        FileStream fs = new FileStream(saveFileDialog1.FileName,
                                       FileMode.Create);
        theInkCanvas.Strokes.Save(fs);
        fs.Close();
    }
}
Private Sub buttonSaveAsClick(ByVal sender As Object, ByVal e As RoutedEventArgs) 

    Dim saveFileDialog1 As New SaveFileDialog()
    saveFileDialog1.Filter = "isf files (*.isf)|*.isf"

    If saveFileDialog1.ShowDialog() Then
        Dim fs As New FileStream(saveFileDialog1.FileName, FileMode.Create)
        theInkCanvas.Strokes.Save(fs)
        fs.Close()
    End If

End Sub 'buttonSaveAsClick

The following example implements a button-click event handler that presents the user with a File Open dialog box and reads ink from the file into an InkCanvas element.

private void buttonLoadClick(object sender, RoutedEventArgs e)
{
    OpenFileDialog openFileDialog1 = new OpenFileDialog();
    openFileDialog1.Filter = "isf files (*.isf)|*.isf";

    if (openFileDialog1.ShowDialog() == true)
    {
        FileStream fs = new FileStream(openFileDialog1.FileName,
                                       FileMode.Open);
        theInkCanvas.Strokes = new StrokeCollection(fs);
        fs.Close();
    }
}
Private Sub buttonLoadClick(ByVal sender As Object, ByVal e As RoutedEventArgs) 

    Dim openFileDialog1 As New OpenFileDialog()
    openFileDialog1.Filter = "isf files (*.isf)|*.isf"

    If openFileDialog1.ShowDialog() Then
        Dim fs As New FileStream(openFileDialog1.FileName, FileMode.Open)
        theInkCanvas.Strokes = New StrokeCollection(fs)
        fs.Close()
    End If

End Sub 'buttonLoadClick

See Also

InkCanvas
Windows Presentation Foundation