예제 #1
0
        private async void MyLoadFileButton_Click(object sender, RoutedEventArgs e)
        {
            //
            FileOpenPicker picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.Desktop;
            picker.ViewMode = PickerViewMode.List;
            picker.FileTypeFilter.Add(".xml");
            StorageFile dataFile = await picker.PickSingleFileAsync();

            if (dataFile == null)
            {
                return;
            }

            //
            List <InkStroke> strokes = await ReadMotionXml(dataFile);

            //
            Sketch motion = new Sketch(strokes, null);

            motion  = SketchTransformation.ScaleProportional(motion, MyBorder.ActualHeight * 0.75);
            motion  = SketchTransformation.TranslateMedian(motion, new Point(MyBorder.ActualWidth / 2, MyBorder.ActualHeight / 2));
            strokes = motion.Strokes;
            strokes[0].DrawingAttributes = LEFT_HAND_VISUALS;
            strokes[1].DrawingAttributes = RIGHT_HAND_VISUALS;

            //
            MyInkCanvas.InkPresenter.StrokeContainer.Clear();
            MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(Gridify());
            MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(strokes);
            MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(Dotify(strokes));
        }
예제 #2
0
        private async void MyLoadFolderButton_Click(object sender, RoutedEventArgs e)
        {
            // open the folder picker dialog window and select the folder with the images
            FolderPicker folderPicker = new FolderPicker();

            folderPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            folderPicker.FileTypeFilter.Add("*");

            // get the folder selection result
            StorageFolder loadFolder = await folderPicker.PickSingleFolderAsync();

            if (loadFolder == null)
            {
                Debug.WriteLine("Operation cancelled.");
                return;
            }

            // application now has read/write access to all contents in the picked folder (including other sub-folder contents)
            StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", loadFolder);

            // get all the sketches
            List <StorageFile> dataFiles = new List <StorageFile>();
            List <StorageFile> loadFiles = (await loadFolder.GetFilesAsync()).ToList();

            foreach (StorageFile file in loadFiles)
            {
                if (Path.GetExtension(file.Name).EndsWith(".xml"))
                {
                    dataFiles.Add(file);
                }
            }

            //
            foreach (StorageFile dataFile in dataFiles)
            {
                //
                List <InkStroke> strokes = await ReadMotionXml(dataFile);

                //
                Sketch motion = new Sketch(strokes, null);
                motion  = SketchTransformation.ScaleProportional(motion, MyBorder.ActualHeight * 0.75);
                motion  = SketchTransformation.TranslateMedian(motion, new Point(MyBorder.ActualWidth / 2, MyBorder.ActualHeight / 2));
                strokes = motion.Strokes;
                strokes[0].DrawingAttributes = LEFT_HAND_VISUALS;
                strokes[1].DrawingAttributes = RIGHT_HAND_VISUALS;

                //
                MyInkCanvas.InkPresenter.StrokeContainer.Clear();
                MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(Gridify());
                MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(strokes);
                MyInkCanvas.InkPresenter.StrokeContainer.AddStrokes(Dotify(strokes));

                //
                StorageFile saveFile = await loadFolder.CreateFileAsync(dataFile.Name + ".gif", CreationCollisionOption.ReplaceExisting);

                try
                {
                    using (IRandomAccessStream stream = await saveFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        await MyInkCanvas.InkPresenter.StrokeContainer.SaveAsync(stream);
                    }
                }
                catch (Exception exception)
                {
                    ;
                }
            }
        }