如何使InkCanvas在UWP的Windows应用程序10的图像? [英] How to render InkCanvas to an image in UWP Windows 10 application?
问题描述
RenderTargetBitmap 类简单的帆布+ InkManager(在Windows 8.1)合作,使墨水笔画的图像。
UWP介绍 InkCanvas 和新的着墨API。但是,它似乎像 RenderTargetBitmap
不与工作。当我尝试捕捉 RenderAsync
方法笔迹,无油墨招搞定呈现唯一的其他对象,如矩形等。
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. However, it seems like the RenderTargetBitmap
does not work with that. When I try to capture ink strokes with RenderAsync
method, no ink strokes get rendered only other objects like Rectangle and so on.
它是一个bug或者是不是意味着这种新的API使用这种方式?如果没有,那么我怎么能渲染图像了 InkCanvas
?
Is it a bug or this new API is not meant to be used this way? If not, then how can I render an image out of InkCanvas
?
谢谢!
推荐答案
下面是我如何解决这一问题Win2D。
:首先, Win2D.uwp
的NuGet包添加到您的项目。
然后用这个代码:
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);
这篇关于如何使InkCanvas在UWP的Windows应用程序10的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!