Reputation: 548
I've been looking for a way to save a Canvas' (Windows.UI.Xaml.Controls) DataContext as an image or get it as a stream. I'm currently using it for drawing on an image and want to save the image with the drawn lines. Maybe I'm doing it wrong, so please enlighten me! :-)
Upvotes: 0
Views: 1040
Reputation: 3619
On UWP I would suggest to use the InkCanvas.
You can store the Strokes like this:
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();
}
}
Upvotes: 2