在localStorage中保存墨迹管理器 - Windows 8应用程序

时间:2013-02-11 08:28:14

标签: c# windows-8 microsoft-metro local-storage

好吧,我尝试了很多东西,但我并不真正理解本地存储中的一切。我知道自相机以来它的工作原理,但我不知道怎么用inkManager来制作它。如果您有任何想法?

这是我保存用户想要的代码,但我希望自动保存"在localstorage:

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)
            {
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

最终解决方案非常简单:

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