不使用SaveFileDialog(UWP)保存InkCanvas笔划

时间:2017-08-07 11:15:30

标签: c# uwp inkcanvas

在我的UWP C#应用程序中,我试图以用户应该能够加载文件并继续编辑笔划的方式保存InkCanvas的笔划,是否可以在不要求用户选择的情况下执行此操作一个位置,而是通过将文件保存到默认位置?

提前致谢

1 个答案:

答案 0 :(得分:0)

您应该在应用的AppData Local文件夹中创建一个文件,并在必要时阅读。我建议使用此代码创建文件:

Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
Windows.Storage.StorageFile file = await storageFolder.CreateFileAsync("sample.gif", Windows.Storage.CreationCollisionOption.ReplaceExisting);

这一个用它写笔画:

Windows.Storage.CachedFileManager.DeferUpdates(file);
IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);
using (IOutputStream outputStream = stream.GetOutputStreamAt(0)) {
   await inkCanvas.InkPresenter.StrokeContainer.SaveAsync(outputStream);
   await outputStream.FlushAsync();
}
stream.Dispose();

Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

if (status == Windows.Storage.Provider.FileUpdateStatus.Complete) {
     // File saved
} else {
     // File NOT saved
}