简体   繁体   中英

(UWP) XAML Canvas to stream

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! :-)

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();
  }
}

Source: https://blogs.windows.com/buildingapps/2015/09/08/going-beyond-keyboard-mouse-and-touch-with-natural-input-10-by-10/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM