我正在使用Microsoft的开源项目的Windows-universal-samples-master \ Samples \ InkAnalysis \ InkAnalysis.sln。它可以分析您绘制的形状,并转换为多边形或椭圆形。
Name Value
---- -----
_id 59cbf243ef32b7bbe22654b4
name Gru Hypue KS-T d3-31 9 b a
system_id 3288878
materials {material_id, material_name, share}
systems {{ "_id" : ObjectId("59cba528ef32b7bbe28a7640"), "id" : 3288878, "edsm_id" : 2749852, "name" : "Gru Hypue KS-T d3-31", "x" : -4990.84375, "y" : -935.71875, "z" : 13387.15625, "population" : 1000...
y {-935.71875}
systemname {Gru Hypue KS-T d3-31}
z {13387.15625}
x {-4990.84375}
所有转换后的形状都被绘制到" canvas",而不是" inkCanvas",因此它们无法保存为墨迹。
如何将形状添加到" inkCanvas"?
答案 0 :(得分:2)
我们可以使用InkStrokeContainer.AddStroke
将InkStroke
对象添加到InkStrokeContainer管理的集合中。如果形状是多边形,我们可以从InkAnalysisInkDrawing.Points
获取点,并通过InkStrokeBuilder
方法将它们设置为CreateStrokeFromInkPoints
。
例如:
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);
}
如果形状是椭圆形,据我所知,我们无法将其添加到InkCanvas
。我们不能得到所有的椭圆,它只提供4个点。