public Stroq(InkStroke inkStroke) { Points = new List<Point>(); foreach (var p in inkStroke.GetInkPoints()) { Points.Add(new Point(p.Position.X, p.Position.Y)); } BackingStroke = inkStroke; }
public Stroke(InkStroke stroke, [CallerMemberName] string methodName = "") { var renderStrokes = stroke.GetRenderingSegments(); StartPoint = renderStrokes.First().Position; foreach (var renderStroke in renderStrokes) { BezierSegments.Add(new BezierSegment { Point1 = renderStroke.BezierControlPoint1, Point2 = renderStroke.BezierControlPoint2, Point3 = renderStroke.Position }); } }
/* #region quadrant ink weight analysis private Rectangle getQuadrantCollision(Line line) { List<Rectangle> quadrants = new List<Rectangle>(); quadrants.Add(box1); quadrants.Add(box2); quadrants.Add(box3); quadrants.Add(box4); foreach (Rectangle quadrant in quadrants) { if (line.X1 > Canvas.GetLeft(quadrant) && line.X1 < Canvas.GetLeft(quadrant) + quadrant.Width && line.Y1 > Canvas.GetTop(quadrant) && line.Y1 < Canvas.GetTop(quadrant) + quadrant.Height) { line.Fill = new SolidColorBrush(Colors.Red); return quadrant; } } return null; } private void analyzeClicked(object sender, RoutedEventArgs e) { //reset the data collection quadWeights[0] = 0; quadWeights[1] = 0; quadWeights[2] = 0; quadWeights[3] = 0; foreach (var stroke in inkManager.GetStrokes()) { foreach (Line line in allLines[stroke]) { Rectangle quad = getQuadrantCollision(line); //increment the counter of the rect with the collision if there was one if (quad != null) { if (quad == box1) { quadWeights[0]++; } else if (quad == box2) { quadWeights[1]++; } else if (quad == box3) { quadWeights[2]++; } else if (quad == box4) { quadWeights[3]++; } dataTextblock.Text = "Top Right: " + quadWeights[0].ToString() + "\n" + "Top Left: " + quadWeights[1].ToString() + "\n" + "Bot Left: " + quadWeights[2].ToString() + "\n" + "Bot Right: " + quadWeights[3].ToString(); } } } } #endregion #region sketch number recognition analysis private int distanceBetweenStrokes(InkStroke stroke1, InkStroke stroke2) { return -1; } private async void recognizedNumberClicked(object sender, RoutedEventArgs e) { //get the available strokes from ink manager and select the strokes var strokes = inkManager.GetStrokes(); foreach (InkStroke stroke in strokes) { //if(stroke.GetRenderingSegments()) //Line startLine = allLines[strokes[0]]; } //set handwriting recognizer var recname = "Microsoft English (US) Handwriting Recognizer"; var recognizers = inkManager.GetRecognizers(); for (int i = 0, len = recognizers.Count; i < len; i++) { if (recname == recognizers[i].Name) { inkManager.SetDefaultRecognizer(recognizers[i]); break; } } //asynchronously recognize the word IReadOnlyList<InkRecognitionResult> recognitionResults = await inkManager.RecognizeAsync(InkRecognitionTarget.All); // Doing a recognition does not update the storage of results (manually update from ink manager) inkManager.UpdateRecognitionResults(recognitionResults); string numbers = ""; foreach (InkRecognitionResult i in recognitionResults) { var candidates = i.GetTextCandidates(); foreach (var possibleWord in candidates) { int num; if (int.TryParse(possibleWord, out num)) { numbers += num + " : "; break; } } } Windows.UI.Popups.MessageDialog mg = new Windows.UI.Popups.MessageDialog(numbers + ""); await mg.ShowAsync(); } #endregion #region sketch correct-time analysis private async void checkTimeClicked(object sender, RoutedEventArgs e) { //for now, assume the last 2 strokes are the 2 hands being drawn var strokes = inkManager.GetStrokes(); foreach(InkStroke stroke in strokes) { //check if this stroke does not have a possible number representation //if it dsnt, check if it starts in/near the center //if it does, check if the slope from the starting line point to the ending line point is correct //if 2 hands have not already been found, then it is one of the hands and do the following: //if 2 hands HAVE been found and another is found, then err //if the hand pointing at 2 is significantly shorter or longer than the circle radius, then err //if the hand pointing at 11 is significantly shorter or longer than half the circle radius, then err } Windows.UI.Popups.MessageDialog mg = new Windows.UI.Popups.MessageDialog(""); await mg.ShowAsync(); } #endregion */ private bool eraserHitTest(InkStroke s, Point testPoint) { foreach (var p in s.GetRenderingSegments()) { if (Math.Abs(testPoint.X - p.Position.X) < 10 && Math.Abs(testPoint.Y - p.Position.Y) < 10) return true; } return false; }
private bool IsPencilStroke(InkStroke stroke) { if (!isPencilSupported) return false; return (stroke.DrawingAttributes.Kind == InkDrawingAttributesKind.Pencil); }
public static bool SameInkStroke(InkStroke first, InkStroke second) { if(first.BoundingRect == second.BoundingRect && first.GetInkPoints().Count == second.GetInkPoints().Count) { return true; } return false; }
/// <summary> /// Renders a single ink stroke as BezierSegments with the given width and color (also opacity) /// </summary> /// <param name="stroke">Stroke to be rendered</param> /// <param name="color">Color to use while rendering the ink stroke</param> /// <param name="width">Size of the stroke</param> /// <param name="opacity">Opacity of the stroke to be created</param> private void RenderStroke(InkStroke stroke, Color color, double width, double opacity = 1) { var renderingStrokes = stroke.GetRenderingSegments(); var path = new Path(); path.Data = new PathGeometry(); ((PathGeometry)path.Data).Figures = new PathFigureCollection(); var pathFigure = new PathFigure(); pathFigure.StartPoint = renderingStrokes.First().Position; ((PathGeometry)path.Data).Figures.Add(pathFigure); foreach (var renderStroke in renderingStrokes) { pathFigure.Segments.Add(new BezierSegment { Point1 = renderStroke.BezierControlPoint1, Point2 = renderStroke.BezierControlPoint2, Point3 = renderStroke.Position }); } path.StrokeThickness = width; path.Stroke = new SolidColorBrush(color); path.Opacity = opacity; m_Canvas.Children.Add(path); }
public Stroq(IList<Point> points, InkStroke backingStroke) { Points = points; BackingStroke = backingStroke; }
public void SyncStroke(InkStrokeContainer containner,double currentCanvasWidth,bool syncAll = true, InkStroke stroke = null) { lock(locker) { try { if (syncAll) { Strokes.Clear(); foreach (var item in containner.GetStrokes()) { InkStroke strokeClone = item.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); Strokes.Add(strokeClone); } } else { if (null != stroke) { InkStroke strokeClone = stroke.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); Strokes.Add(strokeClone); } else { containner.Clear(); foreach (var item in Strokes) { InkStroke strokeClone = item.Clone(); strokeClone.PointTransform = System.Numerics.Matrix3x2.CreateScale((float)(currentCanvasWidth / originalCanvasWidth)); containner.AddStroke(strokeClone); } } } } catch(Exception e) { #if DEBUG System.Diagnostics.Debug.WriteLine(e.Message); #endif } } }
private bool copySelectStroke() { //copy select stroke bool rev = false; IReadOnlyList<InkStroke> listStroke = inkCanvas.InkPresenter.StrokeContainer.GetStrokes(); for(int i = 0;i<listStroke.Count;i++) { if (listStroke[i].Selected) { this.currentSelectStroke = listStroke[i].Clone(); this.currentSelectStroke.Selected = true; selectionCanvas.Children.Clear(); rev = true; break; } } return rev; }
void OnPenColorChanged(object sender, RoutedEventArgs e) { this.FlyoutColor.Hide(); if (this.currentSelectStroke != null) { //clear select Stroke this.ClearSelection(); //set paste color var borderSender = sender as Border; var brush = borderSender.Background as Windows.UI.Xaml.Media.SolidColorBrush; InkDrawingAttributes drawingAttributes = inkCanvas.InkPresenter.CopyDefaultDrawingAttributes(); drawingAttributes.Color = brush.Color; this.currentSelectStroke.DrawingAttributes = drawingAttributes; //add stroke inkCanvas.InkPresenter.StrokeContainer.AddStroke(this.currentSelectStroke); inkCanvas.InkPresenter.StrokeContainer.MoveSelected(new Point(20, 20)); //clear select this.ClearSelection(); this.currentSelectStroke = null; } else { rootPage.ShowMessage("Cannot paste from clipboard."); } }
void OnClear(object sender, Windows.UI.Xaml.RoutedEventArgs e) { //clear all stroke inkCanvas.InkPresenter.StrokeContainer.Clear(); this.currentSelectStroke = null; ClearDrawnBoundingRect(); }