How to render InkCanvas to an image in UWP Windows 10 application?

前端 未结 2 1157
不思量自难忘°
不思量自难忘° 2020-12-03 15:07

The RenderTargetBitmap class worked with simple Canvas + InkManager (in Windows 8.1) to render ink strokes to an image. UWP introduced InkCanvas and a new Inking API. Howeve

相关标签:
2条回答
  • 2020-12-03 15:25

    Here is how I solved this issue with Win2D. First of all, add Win2D.uwp nuget package to your project. Then use this code:

    CanvasDevice device = CanvasDevice.GetSharedDevice();
    CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkCanvas.ActualWidth, (int)inkCanvas.ActualHeight, 96);
    
    using (var ds = renderTarget.CreateDrawingSession())
    {
        ds.Clear(Colors.White);
        ds.DrawInk(inkCanvas.InkPresenter.StrokeContainer.GetStrokes());
    }
    
    using (var fileStream = await file.OpenAsync(FileAccessMode.ReadWrite))
        await renderTarget.SaveAsync(fileStream, CanvasBitmapFileFormat.Jpeg, 1f);
    
    0 讨论(0)
  • 2020-12-03 15:28

    Please try InkPresenter.StrokeContainer property http://blogs.windows.com/buildingapps/2015/09/08/going-beyond-keyboard-mouse-and-touch-with-natural-input-10-by-10/

    0 讨论(0)
提交回复
热议问题