(UWP) XAML Canvas 流式传输

(UWP) XAML Canvas to stream

我一直在寻找一种方法来将 Canvas' (Windows.UI.Xaml.Controls) DataContext 保存为图像或将其作为流获取。我目前正在使用它在图像上绘图,并想用绘制的线条保存图像。可能是我做的不对,请赐教! :-)

在 UWP 上,我建议使用 InkCanvas。

您可以像这样存储笔画:

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/