インクの保存
Save メソッドは、インクをインク シリアル化形式 (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
関連項目
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback