如何在UWP中保存InkCanvas笔划?

时间:2017-09-20 08:55:10

标签: uwp inkcanvas

我想保存网格,网格包含Rectangle和InkCanvas。

<Grid x:Name="mainGrid">
    <Rectangle Fill="Red" Height="100" Width="100"/>
    <InkCanvas x:Name="myCanvas" Height="400" Width="400"
               Margin="0,0,10,10"/>
</Grid>

保存方法代码

        StorageFile file = await savePicker.PickSaveFileAsync();
        RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap();
        await renderTargetBitmap.RenderAsync(mainGrid);
        IBuffer pixels = await renderTargetBitmap.GetPixelsAsync();
        Guid encoderId = BitmapEncoder.PngEncoderId;
        using (var stream = await file.OpenAsync(FileAccessMode.ReadWrite))
        {
            var encoder = await BitmapEncoder.CreateAsync(encoderId, stream);
            encoder.SetPixelData(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth,
                (uint)renderTargetBitmap.PixelHeight, 96, 96, pixels.ToArray());
            await encoder.FlushAsync();
        }

现在保存图像但仅包含矩形,图像中不存在InkCanvas笔划,保存图像后笔画也从输出窗口消失。

任何人都可以建议我,如何使用InkCanvas保存面板?

谢谢..

0 个答案:

没有答案