【问题标题】:(UWP) XAML Canvas to stream(UWP) XAML 画布流式传输
【发布时间】:2015-10-27 14:44:43
【问题描述】:

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

【问题讨论】:

    标签: image xaml canvas stream uwp


    【解决方案1】:

    在 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/

    【讨论】:

    • 完美!感谢您的快速回答!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    相关资源
    最近更新 更多