Example #1
0
        void OnInkPresenterStrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var points = args.Strokes.First()
                         .GetInkPoints()
                         .Select(point => new Point(point.Position.X, point.Position.Y))
                         .ToList();
            var elementPoints = Element.Points;

            elementPoints.Clear();

            foreach (var point in points)
            {
                elementPoints.Add(point);
            }

            if (elementPoints.Count > 0)
            {
                if (Element.DrawingCompletedCommand?.CanExecute(null) ?? false)
                {
                    Element.DrawingCompletedCommand.Execute(elementPoints);
                }
            }

            if (Element.ClearOnFinish)
            {
                Clear();
            }
        }
Example #2
0
        private void DrawingCanvas_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            System.Collections.Generic.IReadOnlyList <InkStroke> strokes = sender.StrokeContainer.GetStrokes();
            StrokeSampleBuilder sampleBuilder = new StrokeSampleBuilder((uint)strokes.Count);

            foreach (InkStroke stroke in strokes)
            {
                System.Collections.Generic.IReadOnlyList <InkPoint> points = stroke.GetInkPoints();
                StrokeBuilder strokeBuilder = new StrokeBuilder((uint)points.Count);

                foreach (InkPoint point in points)
                {
                    strokeBuilder.AddPoint(point.Position.X, point.Position.Y);
                }

                sampleBuilder.AddStroke(strokeBuilder.build());
            }

            StrokeSample sample = sampleBuilder.build();
            Scores       scores = classifier.classify(sample);

            ResultsList.Items.Clear();

            foreach (Score score in scores)
            {
                ResultsList.Items.Add(new SymbolListItem(score.Symbol, score.Value));
            }
        }
        private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            Rect viewBounds = ApplicationView.GetForCurrentView().VisibleBounds;
            Rect inkBounds  = args.Strokes[0].BoundingRect;

            ApplicationData.Current.LocalSettings.Values["X"]      = viewBounds.X + inkBounds.Left;
            ApplicationData.Current.LocalSettings.Values["Y"]      = viewBounds.Y + inkBounds.Top;
            ApplicationData.Current.LocalSettings.Values["Width"]  = Window.Current.Bounds.Width;
            ApplicationData.Current.LocalSettings.Values["Height"] = Window.Current.Bounds.Height;

            var inkPoints = args.Strokes[0].GetInkPoints();
            var rawPoints = new double[inkPoints.Count * 2];

            for (int i = 0; i < inkPoints.Count; i++)
            {
                rawPoints[2 * i]     = inkPoints[i].Position.X - inkBounds.Left;
                rawPoints[2 * i + 1] = inkPoints[i].Position.Y - inkBounds.Top;
            }
            SavePointsToSettings(rawPoints);


            if (ApiInformation.IsApiContractPresent("Windows.ApplicationModel.FullTrustAppContract", 1, 0))
            {
                await FullTrustProcessLauncher.LaunchFullTrustProcessForCurrentAppAsync();
            }
            await Task.Delay(1000);

            sender.StrokeContainer.Clear();
        }
Example #4
0
        private void OnStrokeCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var list = _inkSynchronizer.BeginDry();

            StrokeCollected?.Invoke(this, list);
            _inkSynchronizer.EndDry();
        }
Example #5
0
        private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            try
            {
                IReadOnlyList <InkStroke> currentStrokes = Gana.InkPresenter.StrokeContainer.GetStrokes();
                if (currentStrokes.Count > 0)
                {
                    var recognitionResults = await inkRecognizerContainer.RecognizeAsync(Gana.InkPresenter.StrokeContainer, InkRecognitionTarget.All);

                    if (recognitionResults.Count > 0)
                    {
                        // Display recognition result
                        string str = "";
                        foreach (var r in recognitionResults)
                        {
                            str += r.GetTextCandidates()[0];
                        }
                        CheckCharacter(str, false, currentStrokes.Count);
                    }
                }
            }catch (Exception)
            {
                Gana.InkPresenter.StrokeContainer.Clear();
            }
        }
 void OnStrokesCollected(object sender, InkStrokesCollectedEventArgs args)
 {
     if (LineDrawn != null)
     {
         LineDrawn(this, EventArgs.Empty);
     }
 }
Example #7
0
        async void OnStrokesCollected(
            InkPresenter sender,
            InkStrokesCollectedEventArgs args)
        {
            // create the ink recognizer if we haven't done already.
            if (this.inkRecognizer == null)
            {
                this.inkRecognizer = new InkRecognizerContainer();
            }
            // recognise the ink which has not already been recognised
            // (i.e. do incremental ink recognition).
            var results = await this.inkRecognizer.RecognizeAsync(
                sender.StrokeContainer,
                InkRecognitionTarget.Recent);

            // update the container so that it knows next time that this
            // ink is already recognised.
            sender.StrokeContainer.UpdateRecognitionResults(results);

            // we take all the top results that the recogniser gives us
            // back.
            var newTags = results.Select(
                result => result.GetTextCandidates().FirstOrDefault());

            // add the new tags to our photo.
            await this.photoControl.AddTagsToPhotoAsync(this.currentPhotoId, newTags);
        }
        //SaveNecessity
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            AddStrokeOperation addStrokeOperation = new AddStrokeOperation(args.Strokes.Last());

            ViewModel.UndoRedoBase.AddOperationToUndoneOperations(addStrokeOperation);

            SaveNecessity = true;
        }
Example #9
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var strokes = _synch.BeginDry();

            RenderStrokes(strokes);

            _synch.EndDry();
        }
Example #10
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     //Add back to undoAvailable but only if its less than MaxUndos
     if (undosAvailable < maxUndo)
     {
         undosAvailable += 1;
     }
 }
Example #11
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     foreach (var item in args.Strokes)
     {
         _redoList.Add(item);
     }
     _undoCommand?.RaiseCanExecuteChanged();
     _redoCommand?.RaiseCanExecuteChanged();
 }
Example #12
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            foreach (var s in args.Strokes)
            {
                _inkManager.AddStroke(s);
            }

            //_canvasOne.DrawLine(args.Strokes);
        }
Example #13
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            Job j = DataContext as Job;

            if (j != null)
            {
                IReadOnlyList <InkStroke> strokes = Annotation.InkPresenter.StrokeContainer.GetStrokes();
                j.Strokes = strokes.ToList();
            }
        }
Example #14
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            strokeList.AddRange(args.Strokes);

            foreach (var s in args.Strokes)
            {
                inkManager.AddStroke(s);
            }

            canvasControl.Invalidate();
        }
        private void InkPresenterOnStrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            foreach (var stroke in args.Strokes)
            {
                var strokeId = Guid.NewGuid();

                idToStrokeMapping[strokeId] = stroke;

                strokeChangeBroker.SendStrokeCollected(strokeId, stroke);
            }
        }
 private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     try
     {
         InputReady?.Invoke(this, await MnistHelper.GetHandWrittenImageAsync(inkGrid));
     }
     catch (Exception ex)
     {
         PageService?.ShowNotification(ex.Message);
     }
 }
Example #17
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     foreach (var item in args.Strokes)
     {
         _redoList.Add(item);
     }
     _undoList.Clear();
     _undoCommand?.OnCanExecuteChanged();
     _redoCommand?.OnCanExecuteChanged();
     StrokesChanged?.Invoke(sender, EventArgs.Empty);
 }
Example #18
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs e)
        {
            IReadOnlyList <InkStroke> strokes = e.Strokes;
            string log = $"Strokes collected: {strokes.Count}";

            foreach (InkStroke stroke in strokes)
            {
                log += $"\nId: {stroke.Id}, StartedTime: {stroke.StrokeStartedTime}, Duration: {stroke.StrokeDuration}";
            }
            rootPage.NotifyUser(log, NotifyType.StatusMessage);
        }
        private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            lastModifiedTime = DateTime.Now;
            await Task.Delay(2000);

            if (DateTime.Now - lastModifiedTime > new TimeSpan(0, 0, 2))
            {
                //save only if more than 2 secs from last modification

                await SaveCalendarInk();
            }
        }
        //Detects when the writing strokes are finished
        private void inkCanvas_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            timer.Stop();

            foreach (var stroke in args.Strokes)
            {
                analyzerText.AddDataForStroke(stroke);
                analyzerText.SetStrokeDataKind(stroke.Id, InkAnalysisStrokeKind.Writing);
            }

            timer.Start();
        }
Example #21
0
        void OnStrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            // We tell the framework that we are ready to begin 'drying'.
            // Keep track of the strokes that need to be dried.
            this.wetInkStrokes = this.inkSync.BeginDry();

            // Ensure that our over-all collection of strokes is up to date.
            this.allInkStrokes.AddStrokes(args.Strokes);

            // Cause our control to repaint itself...
            this.canvasControl.Invalidate();
        }
Example #22
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            foreach (var s in args.Strokes)
            {
                inkManager.AddStroke(s);
            }

            Debug.Assert(pendingDry == null);

            pendingDry = inkSynchronizer.BeginDry();

            canvasControl.Invalidate();
        }
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            this.pendingDry = this.inkSynchronizer.BeginDry();
            var container = new InkStrokeContainer();

            foreach (var stroke in this.pendingDry)
            {
                container.AddStroke(stroke.Clone());
            }

            this.strokes.Add(container);
            canvas.Invalidate();
        }
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var strokes   = _inkSynchronizer.BeginDry();
            var container = new InkStrokeContainer();

            container.AddStrokes(from item in strokes
                                 select item.Clone());

            _inkStrokes.Add(container);
            history.Push(_inkStrokes);

            _inkSynchronizer.EndDry();

            DrawingCanvas.Invalidate();
        }
Example #25
0
        /// <summary>
        ///  Render XAML and Ink to preview image
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var renderTargetBitmap = await generateBackground();


            var renderedImageSource = await _inkBitmapRenderer.RenderToImageSourceAsync(
                renderTargetBitmap,
                _inkPresenter.StrokeContainer.GetStrokes(),
                _highlightStrokes.GetStrokes(),
                AnnotationInkCanvas.ActualWidth,
                AnnotationInkCanvas.ActualHeight
                );

            TargetImage.Source = renderedImageSource;
        }
        private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            CanvasDevice       device       = CanvasDevice.GetSharedDevice();
            CanvasRenderTarget renderTarget = new CanvasRenderTarget(device, (int)inkDataCanvas.ActualWidth, (int)inkDataCanvas.ActualHeight, 96);

            using (var ds = renderTarget.CreateDrawingSession())
            {
                ds.Clear(Colors.Black);
                ds.DrawInk(inkDataCanvas.InkPresenter.StrokeContainer.GetStrokes());
            }

            using (var ms = new InMemoryRandomAccessStream())
            {
                await renderTarget.SaveAsync(ms, CanvasBitmapFileFormat.Jpeg, 1);

                await ms.FlushAsync();

                var decoder = await BitmapDecoder.CreateAsync(ms);

                var img = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore);

                var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, ms);

                encoder.BitmapTransform.ScaledHeight = (uint)ViewModelLocator.Instance.Main.ImageSize;
                encoder.BitmapTransform.ScaledWidth  = (uint)ViewModelLocator.Instance.Main.ImageSize;
                encoder.SetSoftwareBitmap(img);
                await encoder.FlushAsync();

                decoder = await BitmapDecoder.CreateAsync(ms);

                img = await decoder.GetSoftwareBitmapAsync(BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore);

                img = SoftwareBitmap.Convert(img, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore);

                var sbs = new SoftwareBitmapSource();
                await sbs.SetBitmapAsync(img);

                inkImage.Source = sbs;

                //var targetImage = new SoftwareBitmap(BitmapPixelFormat.Bgra8, img.PixelWidth, img.PixelHeight);
                // img.CopyTo(targetImage);
                ViewModelLocator.Instance.Main.CurrentInkImage = ms.CloneStream();
                ms.Dispose();
            }
        }
        void OnInkPresenterStrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs e)
        {
            Element.Lines.CollectionChanged -= OnCollectionChanged;
            if (e.Strokes.Count > 0)
            {
                if (!Element.MultiLineMode)
                {
                    Element.Lines.Clear();
                }

                var lines = Element.MultiLineMode ? e.Strokes : new List <InkStroke>()
                {
                    e.Strokes.First()
                };

                foreach (var line in lines)
                {
                    var points = line.GetInkPoints().Select(point => new Point(point.Position.X, point.Position.Y));
                    Element.Lines.Add(new Line()
                    {
                        Points    = new ObservableCollection <Point>(points),
                        LineColor = Color.FromRgba(line.DrawingAttributes.Color.R, line.DrawingAttributes.Color.G,
                                                   line.DrawingAttributes.Color.B, line.DrawingAttributes.Color.A),
                        LineWidth = (float)line.DrawingAttributes.Size.Width
                    });
                }

                if (Element.Lines.Count > 0)
                {
                    var lastLine = Element.Lines.Last();
                    Element.OnDrawingLineCompleted(lastLine);
                }

                if (Element.ClearOnFinish)
                {
                    Element.Lines.CollectionChanged -= OnCollectionChanged;
                    Clear(true);
                    Element.Lines.CollectionChanged += OnCollectionChanged;
                }
            }

            Element.Lines.CollectionChanged += OnCollectionChanged;
        }
        //Detects when the writing strokes are finished
        private void inkCanvas_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            timer.Stop();

            for (int i = 0; i < inkCanvas.Length; i++)
            {
                if (inkCanvas[i].InkPresenter == sender)
                {
                    currentCanvasNumber = i;
                }
            }

            foreach (var stroke in args.Strokes)
            {
                analyzerText.AddDataForStroke(stroke);
                analyzerText.SetStrokeDataKind(stroke.Id, InkAnalysisStrokeKind.Writing);
            }

            timer.Start();
        }
Example #29
0
        private void StrokeInput_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            if (this.IsSkritter == true)
            {
                var          strokes    = this.WritingInkCanvas.InkPresenter.StrokeContainer.GetStrokes();
                SketchStroke lastStroke = new SketchStroke(strokes[strokes.Count - 1], this.timeCollection[this.timeCollection.Count - 1]);

                if (SkritterHelpers.ValidateStroke(lastStroke, this.currentTemplateSketchStrokes[this.sketchStrokes.Count]) == true)
                {
                    this.sketchStrokes.Add(lastStroke);
                    InteractionTools.ShowStroke(this.AnimationCanvas, this.currentTemplateSketchStrokes[this.sketchStrokes.Count - 1]);
                }
                else
                {
                    this.timeCollection.RemoveAt(this.timeCollection.Count - 1);
                }

                strokes[strokes.Count - 1].Selected = true;
                this.WritingInkCanvas.InkPresenter.StrokeContainer.DeleteSelected();
            }
        }
Example #30
0
        private async void InkPresenter_StrokesCollectedAsync(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            var bitmap = Inker.GetCropedSoftwareBitmap(newWidth: 227, newHeight: 227, keepRelativeSize: true);
            var frame  = VideoFrame.CreateWithSoftwareBitmap(bitmap);
            var input  = new ModelInput()
            {
                data = frame
            };

            var output = await model.EvaluateAsync(input);

            var guessedTag        = output.classLabel.First();
            var guessedPercentage = output.loss.OrderByDescending(kv => kv.Value).First().Value;

            if (guessedPercentage < 0.9)
            {
                SubText.Text = $"draw {currentShape} to snooze - don't know what that is";
            }
            else if (guessedTag != currentShape)
            {
                SubText.Text = $"draw {currentShape} to snooze - you drew {guessedTag}";
            }
            else
            {
                AlarmOn = false;
                foreach (var stroke in Inker.InkPresenter.StrokeContainer.GetStrokes())
                {
                    var attributes = stroke.DrawingAttributes;
                    attributes.PencilProperties.Opacity = 1;
                    attributes.Color         = Colors.DarkBlue;
                    attributes.Size          = new Size(60, 60);
                    stroke.DrawingAttributes = attributes;
                    stroke.PointTransform    = Matrix3x2.CreateScale(2, new Vector2((float)ActualWidth / 2, (float)ActualHeight / 2));
                }
            }

            Debug.WriteLine($"Current guess: {guessedTag}({guessedPercentage})");
        }
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     timer.Start();
 }
Example #32
0
 /// <summary>
 /// Start countdown timer once the user has finished inking
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="args"></param>
 private void InkCanvas_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     pointerTimer.Stop();
     recognitionTimer.Start();
 }
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            try
            {
                ((App)App.Current).SyncStrokeEx(strokeMapping, ink.InkPresenter.StrokeContainer, ink.Width);
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debug.WriteLine(e.Message);
#endif
            }
        }
Example #34
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {            
     saved = false;
 }
Example #35
0
 private async void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     // Notify user about the risk when using inking for the first time.
     if ((bool)App.AppSettings[App.INKING_WARNING])
     {
         int userResponse = await App.NotifyUserWithOptions(Messages.INK_STROKE_WARNING,
             new string[] { "OK, do not show this again.", "Notify me again next time." });
         switch (userResponse)
         {
             case 0: // Do not show again
                 ApplicationData.Current.RoamingSettings.Values[App.INKING_WARNING] = false;
                 App.AppSettings[App.INKING_WARNING] = false;
                 break;
             default:
                 App.AppSettings[App.INKING_WARNING] = false;
                 break;
         }
     }
     int p = findPageNumberByInkPresenter(sender);
     await inkManager.addStrokes(p, sender.StrokeContainer, args.Strokes);
 }
    async void OnStrokesCollected(
      InkPresenter sender,
      InkStrokesCollectedEventArgs args)
    {
      // create the ink recognizer if we haven't done already.
      if (this.inkRecognizer == null)
      {
        this.inkRecognizer = new InkRecognizerContainer();
      }
      // recognise the ink which has not already been recognised
      // (i.e. do incremental ink recognition).
      var results = await this.inkRecognizer.RecognizeAsync(
        sender.StrokeContainer,
        InkRecognitionTarget.Recent);

      // update the container so that it knows next time that this
      // ink is already recognised.
      sender.StrokeContainer.UpdateRecognitionResults(results);

      // we take all the top results that the recogniser gives us
      // back.
      var newTags = results.Select(
        result => result.GetTextCandidates().FirstOrDefault());

      // add the new tags to our photo.
      await this.photoControl.AddTagsToPhotoAsync(this.currentPhotoId, newTags);
    }
Example #37
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            strokeList.AddRange(args.Strokes);
            
            foreach (var s in args.Strokes)
            {
                inkManager.AddStroke(s);
            }

            canvasControl.Invalidate();
        }
Example #38
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     rootPage.NotifyUser(args.Strokes.Count + " stroke(s) collected!", NotifyType.StatusMessage);
 }
Example #39
0
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     System.Diagnostics.Debug.WriteLine("InkPresenter_StrokesCollected");
     timer.Start();
 }
 private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
 {
     SendInk();
 }
Example #41
0
        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            foreach (var s in args.Strokes)
            {
                inkManager.AddStroke(s);
            }

            Debug.Assert(pendingDry == null);

            pendingDry = inkSynchronizer.BeginDry();

            canvasControl.Invalidate();
        }
Example #42
0
        /* Event Handlers */

        private void InkPresenter_StrokesCollected(InkPresenter sender, InkStrokesCollectedEventArgs args)
        {
            RecogniseText();
        }