[uwp] [Xaml]如何将墨迹转换为点| InkingManager [英] [uwp][Xaml] How to Convert Ink Strokes to Points | InkingManager

查看:98
本文介绍了[uwp] [Xaml]如何将墨迹转换为点| InkingManager的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码作为我的签名板。我想要的是,我想转换路径到点我怎么能!谢谢!


https://social.msdn.microsoft.com/Forums/vstudio/en-US/94c0497e-6363-4c87-a071-5d9576764820/w81ctouch-doesnt-work?forum = wpdevelop

 private void RenderAllStrokes()
{
try
{
//清除画布。

//获取InkStroke对象。
IReadOnlyList< InkStroke> inkStrokes = _inkManager.GetStrokes();
InkStrokeBuilder inkstkbuilder = new InkStrokeBuilder();
//处理每个笔划。
foreach(InkStroke中的InkStroke inkStroke)
{
PathGeometry pathGeometry = new PathGeometry();
PathFigureCollection pathFigures = new PathFigureCollection();
PathFigure pathFigure = new PathFigure();
PathSegmentCollection pathSegments = new PathSegmentCollection();

//创建路径并定义其属性。
// Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path();
Path path = new Path();
path.Stroke = new SolidColorBrush(Colors.Black);
path.StrokeThickness = STROKETHICKNESS;

//获取笔划段。
IReadOnlyList< InkStrokeRenderingSegment>段;
segments = inkStroke.GetRenderingSegments();

//处理每个笔划段。
bool first = true;
foreach(段中的InkStrokeRenderingSegment段)
{
//第一段是路径的起点。
if(first)
{
pathFigure.StartPoint = segment.BezierControlPoint1;
first = false;
}

//将每个墨水段复制到贝塞尔曲线段。
BezierSegment bezSegment = new BezierSegment();
bezSegment.Point1 = segment.BezierControlPoint1;
bezSegment.Point2 = segment.BezierControlPoint2;
bezSegment.Point3 = segment.Position;

//将贝塞尔曲线段添加到路径中。
pathSegments.Add(bezSegment);
}

//构建路径geometerty对象。
pathFigure.Segments = pathSegments;
pathFigures.Add(pathFigure);
pathGeometry.Figures = pathFigures;

//将路径几何对象指定为路径数据。
path.DataContext = pathGeometry;

//通过将路径添加为Canvas对象的子项来渲染路径。
InkCanvas.Children.Add(path);
}
}
catch(exception ex)
{
Debug.WriteLine(ex.Message,ex.StackTrace);
}
}





Charu

解决方案

Hello Charu,


如何更具体地解决这个问题?例如,您希望获得什么样的效果。我猜你也许想得到一个积分来创建一个虚线?如果是这种情况,也许您可​​以考虑使用Polyline,就像提到的UWP样本


https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/SimpleInk/cs/Scenario3.xaml .cs


您将在其中找到以下代码:

 private void UnprocessedInput_PointerPressed(InkUnprocessedInput sender,Windows。 UI.Core.PointerEventArgs args)
{
lasso = new Polyline()
{
Stroke = new SolidColorBrush(Windows.UI.Colors.Blue),
StrokeThickness = 1,
StrokeDashArray = new DoubleCollection(){5,2},
};

lasso.Points.Add(args.CurrentPoint.RawPosition);

selectionCanvas.Children.Add(lasso);
}

通过这种方式,您可以创建一个虚线。然而,在我看来,最好的路径也包含

StrokeDashArray


如果这不是您想要的,请更具体。我不是这样的 确定你的要求。


祝你好运,


Barry




i am using following code for my signature pad. what i want is,i  want to convert Path to Points how can i ! Thanks !

https://social.msdn.microsoft.com/Forums/vstudio/en-US/94c0497e-6363-4c87-a071-5d9576764820/w81ctouch-doesnt-work?forum=wpdevelop

  private void RenderAllStrokes()
        {
            try
            {
                // Clear the canvas.

                // Get the InkStroke objects.
                IReadOnlyList<InkStroke> inkStrokes = _inkManager.GetStrokes();
                InkStrokeBuilder inkstkbuilder = new InkStrokeBuilder();
                // Process each stroke.
                foreach (InkStroke inkStroke in inkStrokes)
                {
                    PathGeometry pathGeometry = new PathGeometry();
                    PathFigureCollection pathFigures = new PathFigureCollection();
                    PathFigure pathFigure = new PathFigure();
                    PathSegmentCollection pathSegments = new PathSegmentCollection();

                    // Create a path and define its attributes.
                    // Windows.UI.Xaml.Shapes.Path path = new Windows.UI.Xaml.Shapes.Path();
                    Path path = new Path();
                    path.Stroke = new SolidColorBrush(Colors.Black);
                    path.StrokeThickness = STROKETHICKNESS;

                    // Get the stroke segments.
                    IReadOnlyList<InkStrokeRenderingSegment> segments;
                    segments = inkStroke.GetRenderingSegments();

                    // Process each stroke segment.
                    bool first = true;
                    foreach (InkStrokeRenderingSegment segment in segments)
                    {
                        // The first segment is the starting point for the path.
                        if (first)
                        {
                            pathFigure.StartPoint = segment.BezierControlPoint1;
                            first = false;
                        }

                        // Copy each ink segment into a bezier segment.
                        BezierSegment bezSegment = new BezierSegment();
                        bezSegment.Point1 = segment.BezierControlPoint1;
                        bezSegment.Point2 = segment.BezierControlPoint2;
                        bezSegment.Point3 = segment.Position;

                        // Add the bezier segment to the path.
                        pathSegments.Add(bezSegment);
                    }

                    // Build the path geometerty object.
                    pathFigure.Segments = pathSegments;
                    pathFigures.Add(pathFigure);
                    pathGeometry.Figures = pathFigures;

                    // Assign the path geometry object as the path data.
                    path.DataContext = pathGeometry;
                   
                    // Render the path by adding it as a child of the Canvas object.
                    InkCanvas.Children.Add(path);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message, ex.StackTrace);
            }
        }


Charu

解决方案

Hello Charu,

What about be more specific to this issue? For example, what kind of effect do you want to get. I'm guessing that maybe you want to get a collection of points to create a dashline? If that is the case maybe you can consider to use Polyline like the UWP sample mentioned:

https://github.com/Microsoft/Windows-universal-samples/blob/master/Samples/SimpleInk/cs/Scenario3.xaml.cs

Where you will find the following code:

  private void UnprocessedInput_PointerPressed(InkUnprocessedInput sender, Windows.UI.Core.PointerEventArgs args)
        {
            lasso = new Polyline()
            {
                Stroke = new SolidColorBrush(Windows.UI.Colors.Blue),
                StrokeThickness = 1,
                StrokeDashArray = new DoubleCollection() {5, 2},
            };

            lasso.Points.Add(args.CurrentPoint.RawPosition);

            selectionCanvas.Children.Add(lasso);
        }

In this way you can create a dashline. However path in my mind is the best which also contains StrokeDashArray.

If that is not what you want, please be more specific. I'm not so  sure about your requirement.

Best regards,

Barry


这篇关于[uwp] [Xaml]如何将墨迹转换为点| InkingManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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