首页 文章

(UWP)XAML Canvas要流式传输

提问于
浏览
0

我一直在寻找一种方法将Canvas'(Windows.UI.Xaml.Controls)DataContext保存为图像或将其作为流来获取 . 我正在使用它来绘制图像,并希望用绘制的线条保存图像 . 也许我做错了,所以请赐教! :-)

1 回答

  • 2

    在UWP上,我建议使用InkCanvas .

    你可以像这样存储Strokes:

    var savePicker = new FileSavePicker();
    savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
    savePicker.FileTypeChoices.Add("Gif with embedded ISF", new
    System.Collections.Generic.List<string> { ".gif" }); 
    
    StorageFile file = await savePicker.PickSaveFileAsync();
    if (null != file)
    {
      try
      {
        using (IRandomAccessStream stream = await file.OpenAsync(FileAccessMode.ReadWrite))
        {
          await myInkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
        }
      }
      catch (Exception ex)
      {
        GenerateErrorMessage();
      }
    }
    

    资料来源:https://blogs.windows.com/buildingapps/2015/09/08/going-beyond-keyboard-mouse-and-touch-with-natural-input-10-by-10/

相关问题