儲存筆墨
更新:2007 年 11 月
Save 方法支援將筆墨儲存成筆墨序列化格式 (Ink Serialized Format,ISF)。StrokeCollection 類別的建構函式支援讀取筆墨資料。
筆墨儲存和擷取
本節討論如何在 WPF 平台中儲存和擷取筆墨。
下列範例會實作按鈕動作事件處理常式,會向使用者顯示 [儲存檔案] 對話方塊並將 InkCanvas 中的筆墨儲存至檔案。
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
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();
}
}
下列範例會實作按鈕動作事件處理常式,會向使用者顯示 [開啟檔案] 對話方塊並從檔案將筆墨讀取至 InkCanvas 項目中。
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
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();
}
}