在localStorage-windows 8应用程序中保存墨迹管理器的笔划

本文关键字:管理器 保存 localStorage-windows 应用程序 | 更新日期: 2023-09-27 17:58:33

我尝试了很多东西,但我并不是真正理解本地存储中保存的所有内容。自从相机问世以来,我就知道它是如何工作的,但我不知道如何使用inkManager。如果你有什么想法?

这是我的代码,可以保存到用户想要的地方,但我想在本地存储中"自动保存":

private async void save_Button(object sender, RoutedEventArgs e)
    {
        if (_inkManager.GetStrokes().Count > 0)
        {
            try
            {
                Windows.Storage.Pickers.FileSavePicker save = new Windows.Storage.Pickers.FileSavePicker();
                save.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop;
                save.DefaultFileExtension = ".jpg";
                save.FileTypeChoices.Add("JPG", new string[] { ".jpg" });
                StorageFile filesave = await save.PickSaveFileAsync();
                IOutputStream ab = await filesave.OpenAsync(FileAccessMode.ReadWrite);
                if (ab != null)
                    await _inkManager.SaveAsync(ab);
              //  await save.CopyAsync(ApplicationData.Current.LocalFolder, "merge1.jpg");
                if (save != null)
                {
                    Clipboard.Source = new Windows.UI.Xaml.Media.Imaging.BitmapImage(new Uri("ms-appdata:///local/merge1.jpg"));
                }
            }
            catch (Exception)
            {
            }
        }
    }

在localStorage-windows 8应用程序中保存墨迹管理器的笔划

最终解决方案相当简单:

StorageFile myMerge = await ApplicationData.Current.LocalFolder.CreateFileAsync("myimg.png");
IOutputStream ac = await myMerge.OpenAsync(FileAccessMode.ReadWrite);
if (ac != null)
    await _inkManager.SaveAsync(ac);