インクの格納

Save メソッドでは、Ink Serialized Format (ISF) としてインクを格納するためのサポートが提供されます。 StrokeCollection クラスのコンストラクターからは、インク データを読み取るためのサポートが提供されます。

インクの格納と取得

このセクションでは、WPF プラットフォームでインクを格納し、取得する方法について説明します。

次の例では、[ファイルの保存] ダイアログ ボックスをユーザーに提示し、InkCanvas からファイルにインクを保存するボタンクリック イベント ハンドラーが実装されます。

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

次の例では、[ファイルを開く] ダイアログ ボックスをユーザーに提示し、ファイルから InkCanvas 要素にインクを読み込むボタンクリック イベント ハンドラーが実装されます。

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

関連項目