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)); } }
internal DrawingboardData GetModel() { DrawingboardData data = new DrawingboardData(); var strokesData = StrokeBuilder.StrokesToData(inkCanvas.Strokes, new Size(inkCanvas.ActualWidth, inkCanvas.ActualHeight)); data.ID = this.ID; data.Strokes = strokesData; return(data); }
void SaveContentInBackground(object o) { DrawingboardData data = o as DrawingboardData; if (data != null) { bool result = StrokeBuilder.Save(data); if (result) { } } }
private void Drawingboard_Loaded(object sender, RoutedEventArgs e) { AttachGesture(); if (this.data != null) { if (this.inkCanvas.Strokes != null) { this.inkCanvas.Strokes.StrokesChanged -= Strokes_StrokesChanged; } this.inkCanvas.Strokes = StrokeBuilder.DataToStrokes(this.data.Strokes, new Size(this.inkCanvas.ActualWidth, this.inkCanvas.ActualHeight)); this.inkCanvas.Strokes.StrokesChanged += Strokes_StrokesChanged; } }
void Save(DrawingboardData content, RenderTargetBitmap snapShotSource) { string fileName = content.ID; string snapShotAddress = StrokeBuilder.GetSnapShotAddresss(fileName); try { snapShotSource.Save(snapShotAddress); Thread saveThread = new Thread(this.SaveContentInBackground); saveThread.Start(content); } catch (Exception ex) { return; } }
private void Load() { if (this.isLoadFiles == false) { this.isLoadFiles = true; string fileDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, StrokeBuilder.FileDirectory); if (Directory.Exists(fileDirectory) == false) { Directory.CreateDirectory(fileDirectory); } string snapShotDirectory = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, StrokeBuilder.SnapshotDirectory); if (Directory.Exists(snapShotDirectory) == false) { Directory.CreateDirectory(snapShotDirectory); } else { string[] files = Directory.GetFiles(snapShotDirectory); IEnumerable <string> orderFiles = files.OrderBy(item => item); char[] split = { '\\' }; foreach (string file in orderFiles) { string[] filepath = file.Split(split); string fileName = filepath[filepath.Length - 1]; int index = fileName.IndexOf('.'); string fileId = fileName.Substring(0, index); Image img = new Image(); img.SetImage(file, true); DrawingboardData data = StrokeBuilder.Load(fileId); if (data != null) { this.boards.Add(fileId, data); this.Add(img, fileId); } } } } }