private async void MyTransformButton_Click(object sender, RoutedEventArgs e) { int resample = int.Parse(MyResampleText.Text); double scale = double.Parse(MyScaleText.Text); double x = double.Parse(MyTranslateX.Text); double y = double.Parse(MyTranslateY.Text); Point point = new Point(x, y); foreach (StorageFile loadFile in myLoadFiles) { string loadFileName = loadFile.Name; Sketch sketch = await SketchTools.XmlToSketch(loadFile); if (MyResampleCheckBox.IsChecked.Value) { sketch = SketchTransformation.Resample(sketch, resample); } if (MyScaleCheckBox.IsChecked.Value) { sketch = SketchTransformation.ScaleFrame(sketch, scale); } if (MyTranslateCheckBox.IsChecked.Value) { sketch = SketchTransformation.TranslateFrame(sketch, point); } StorageFile saveFile = await mySaveFolder.CreateFileAsync(loadFileName, CreationCollisionOption.ReplaceExisting); SketchTools.SketchToXml(saveFile, sketch.Label, sketch.Strokes, sketch.Times, sketch.FrameMinX, sketch.FrameMinY, sketch.FrameMaxX, sketch.FrameMaxY); } }
private void MyPage_Loaded(object sender, RoutedEventArgs e) { // initializer the feedback recognizers myStructureRecognizer = new StructureRecognizer(); myTechniqueRecognizer = new TechniqueRecognizer(); // squarify the ink canvas' drawing area double width = MyBorder.ActualWidth; double height = MyBorder.ActualHeight; BorderLength = width < height ? width : height; MyBorder.Width = MyBorder.Height = BorderLength; // initialize the external timing data structure and offset myTimeCollection = new List <List <long> >(); MyDateTimeOffset = 0; // enable writing and set the stroke visuals of the ink canvas MyInkStrokes = MyInkCanvas.InkPresenter.StrokeContainer; MyInkCanvas.InkPresenter.InputDeviceTypes = CoreInputDeviceTypes.Pen | CoreInputDeviceTypes.Mouse | CoreInputDeviceTypes.Touch; MyInkCanvas.InkPresenter.UpdateDefaultDrawingAttributes(StrokeVisuals); // load the images and templates LoadContents(IMAGES_PATH, out myImageFiles, ".png"); LoadContents(TEMPLATES_PATH, out myTemplateFiles, ".xml"); // populate the symbols combo box foreach (StorageFile file in myImageFiles) { MySymbolsComboBox.Items.Add(Path.GetFileNameWithoutExtension(file.Path)); } MySymbolsComboBox.SelectedIndex = 0; // set the prompt text string promptedSymbol = MySymbolsComboBox.SelectedValue.ToString().ToUpper(); MyPrompText.Text = PROMPT_TEXT + promptedSymbol; // modify the templates to fit the current ink canvas' drawing area myTemplates = new List <Sketch>(); foreach (StorageFile file in myTemplateFiles) { Sketch template = null; Task task = Task.Run(async() => template = await SketchTools.XmlToSketch(file)); task.Wait(); template = SketchTransformation.ScaleFrame(template, BorderLength); template = SketchTransformation.TranslateFrame(template, new Point(BorderLength / 2 - MyBorder.BorderThickness.Left, BorderLength / 2 - MyBorder.BorderThickness.Top)); myTemplates.Add(template); foreach (InkStroke stroke in template.Strokes) { stroke.DrawingAttributes = StrokeVisuals; } } // set the flag to allow buttons to run code MyIsReady = true; }