Image (UWP)要流的XAML画布

Image (UWP)要流的XAML画布,image,xaml,canvas,stream,uwp,Image,Xaml,Canvas,Stream,Uwp,我一直在寻找一种将Canvas'(Windows.UI.Xaml.Controls)数据上下文保存为图像或获取为流的方法。我目前正在使用它在图像上绘制,并希望用绘制的线条保存图像。也许我做错了,所以请开导我!:-) 对于UWP,我建议使用InkCanvas 可以按如下方式存储笔划: var savePicker = new FileSavePicker(); savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLoc

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

对于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();
  }
}
var savePicker=new FileSavePicker();
savePicker.SuggestedStartLocation=Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
savePicker.FileTypeChoices.Add(“嵌入ISF的Gif”,新增
System.Collections.Generic.List{.gif});
StorageFile file=wait savePicker.PickSaveFileAsync();
if(null!=文件)
{
尝试
{
使用(irandomaccesstream=await file.OpenAsync(FileAccessMode.ReadWrite))
{
等待myInkCanvas.InkPresenter.StrokeContainer.SaveAsync(流);
}
}
捕获(例外情况除外)
{
GenerateErrorMessage();
}
}
资料来源:

完美!谢谢你的快速回答!