[英]How to render InkCanvas to an image in UWP Windows 10 application?
The RenderTargetBitmap class worked with simple Canvas + InkManager (in Windows 8.1) to render ink strokes to an image. RenderTargetBitmap类与简单的Canvas + InkManager(在Windows 8.1中)一起使用,可将笔触渲染到图像上。 UWP introduced InkCanvas and a new Inking API.
UWP引入了InkCanvas和新的Inking API。 However, it seems like the
RenderTargetBitmap
does not work with that. 但是,似乎
RenderTargetBitmap
对此不起作用。 When I try to capture ink strokes with RenderAsync
method, no ink strokes get rendered only other objects like Rectangle and so on. 当我尝试使用
RenderAsync
方法捕获笔触时,没有笔触仅渲染其他对象(如Rectangle等)。
Is it a bug or this new API is not meant to be used this way? 是错误还是此新API不能以这种方式使用? If not, then how can I render an image out of
InkCanvas
? 如果没有,那么如何从
InkCanvas
渲染图像?
Thanks! 谢谢!
Here is how I solved this issue with Win2D. 这是我使用Win2D解决此问题的方法。 First of all, add
Win2D.uwp
nuget package to your project. 首先,将
Win2D.uwp
nuget包添加到您的项目中。 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);
请尝试InkPresenter.StrokeContainer属性http://blogs.windows.com/buildingapps/2015/09/08/going-beyond-keyboard-mouse-and-touch-with-natural-input-10-by-10/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.