【发布时间】:2015-10-27 14:44:43
【问题描述】:
我一直在寻找将 Canvas 的 (Windows.UI.Xaml.Controls) DataContext 保存为图像或将其作为流获取的方法。我目前正在使用它在图像上绘图,并希望用绘制的线条保存图像。也许我做错了,所以请赐教! :-)
【问题讨论】:
标签: image xaml canvas stream uwp
我一直在寻找将 Canvas 的 (Windows.UI.Xaml.Controls) DataContext 保存为图像或将其作为流获取的方法。我目前正在使用它在图像上绘图,并希望用绘制的线条保存图像。也许我做错了,所以请赐教! :-)
【问题讨论】:
标签: image xaml canvas stream uwp
在 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();
}
}
【讨论】: