在 uwp 中将多边形/椭圆添加到inkcanvas [英] Add polygon/ellipse to inkcanvas in uwp

查看:32
本文介绍了在 uwp 中将多边形/椭圆添加到inkcanvas的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Microsoft 开源项目的 Windows-universal-samples-master\Samples\InkAnalysis\InkAnalysis.sln.它可以分析您绘制的形状,并转换为多边形或椭圆.

所有转换后的形状都绘制到canvas",而不是inkCanvas",所以它们不能保存为ink.

如何将形状添加到inkCanvas"中?

解决方案

我们可以使用 InkStrokeContainer.AddStroke 以将 InkStroke 对象添加到 InkStrokeContainer 管理的集合中.如果形状是多边形,我们可以从InkAnalysisInkDrawing.Points中获取点,并通过CreateStrokeFromInkPoints方法将它们设置到InkStrokeBuilder.>

例如:

private void AddPolygonToInkCanvas(InkAnalysisInkDrawing shape){var strokeBuilder = new InkStrokeBuilder();var strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();strokeBuilder.SetDefaultDrawingAttributes(strokes[0].DrawingAttributes);System.Numerics.Matrix3x2 matr = strokes[0].PointTransform;列表<InkPoint>inkPointslist = new List();foreach (var item in shape.Points){var intpoint = new InkPoint(new Point(item.X, item.Y), 0.5f);inkPointslist.Add(intpoint);}var lastintpoint = new InkPoint(new Point(shape.Points[0].X, shape.Points[0].Y), 0.5f);inkPointslist.Add(lastintpoint);IReadOnlyList墨水点 = 墨水点列表;InkStroke stroke = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);}

如果形状是椭圆形,据我所知我们不能将它添加到InkCanvas.我们不能得到所有的椭圆,它只提供 4 分.

I'm using Windows-universal-samples-master\Samples\InkAnalysis\InkAnalysis.sln of Microsoft's open source project. It can analysis the shape you draw, and convert to polygon or ellipse.

<Grid
<Canvas x:Name="canvas"/>
<InkCanvas x:Name="inkCanvas"/>
</Grid>

All the converted shapes are drawn to "canvas", not "inkCanvas", so they can not be saved as ink.

How to add the shapes to "inkCanvas"?

解决方案

We can use InkStrokeContainer.AddStroke to add to an InkStroke object to the collection managed by the InkStrokeContainer. If the shape is polygon, We can get the point from the InkAnalysisInkDrawing.Points and set them to the InkStrokeBuilder by the CreateStrokeFromInkPoints method.

For example:

private void AddPolygonToInkCanvas(InkAnalysisInkDrawing shape)
{
    var strokeBuilder = new InkStrokeBuilder();
    var strokes = inkCanvas.InkPresenter.StrokeContainer.GetStrokes();
    strokeBuilder.SetDefaultDrawingAttributes(strokes[0].DrawingAttributes);
    System.Numerics.Matrix3x2 matr = strokes[0].PointTransform;
    List<InkPoint> inkPointslist = new List<InkPoint>();
    foreach (var item in shape.Points)
    {
        var intpoint = new InkPoint(new Point(item.X, item.Y), 0.5f);
        inkPointslist.Add(intpoint);
    }
    var lastintpoint = new InkPoint(new Point(shape.Points[0].X, shape.Points[0].Y), 0.5f);
    inkPointslist.Add(lastintpoint);
    IReadOnlyList<InkPoint> inkPoints = inkPointslist;
    InkStroke stroke = strokeBuilder.CreateStrokeFromInkPoints(inkPoints, matr);  
    inkCanvas.InkPresenter.StrokeContainer.AddStroke(stroke);
}

If the shape is ellipse, as far as I known we can not add it to the InkCanvas. We can not get the all of the ellipse, it only provides 4 points.

这篇关于在 uwp 中将多边形/椭圆添加到inkcanvas的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆