Ejemplo n.º 1
0
        private async Task DoPickImageFile()
        {
            try
            {
                var picker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.Thumbnail,
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary
                };
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".jpeg");
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".bmp");
                picker.FileTypeFilter.Add(".gif");

                var file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    var stream = await file.OpenAsync(FileAccessMode.Read);

                    var bitmapImage = new BitmapImage();
                    await bitmapImage.SetSourceAsync(stream);

                    CurrentImageSource = bitmapImage;

                    ImagePixelHeight = bitmapImage.PixelHeight;
                    ImagePixelWidth  = bitmapImage.PixelWidth;

                    RaisePropertyChanged(nameof(ImageResolution));

                    var tempFolder = ApplicationData.Current.TemporaryFolder;
                    var copiedFile = await file.CopyAsync(tempFolder, $"Tracing_Temp{file.FileType}", NameCollisionOption.ReplaceExisting);

                    InkOperator.ApplyImageFile(copiedFile);
                }
            }
            catch (Exception ex)
            {
                var msg = $"{nameof(DoPickImageFile)}(): {ex.Message}";
                await DialogService.ShowMessageBox(msg,
                                                   Utils.GetResource("Resources/MessageDialogTitle-Error"));
            }
        }
Ejemplo n.º 2
0
        public MainViewModel(IDialogService dialogService)
        {
            DialogService = dialogService;

            CommandToggleFullScreen = new RelayCommand(ToggleFullScreenMode);
            CommandPrint            = new RelayCommand(async() => await DoPrintAsync());
            CommandExportInkToImage = new RelayCommand <ImageSavingOptions>(async opt => await SaveImageAsync(opt));
            CommandSaveAsInkFile    =
                new RelayCommand(async() => await SaveAsInkFileAsync(_defaultInkFilePickerLocation));
            CommandSaveAsGifFile =
                new RelayCommand(async() => await SaveAsGifFileAsync(_defaultInkFilePickerLocation));
            CommandSaveCurrent               = new RelayCommand(async() => await SaveCurrentSessionAsync());
            CommandUndo                      = new RelayCommand(() => { InkOperator?.UndoLastStorke(); });
            CommandRedo                      = new RelayCommand(() => { InkOperator?.RedoLastStorke(); });
            CommandLoadInkFile               = new RelayCommand(async() => await OpenInkFile(_defaultInkFilePickerLocation));
            ClearImageSource                 = new RelayCommand(() => { CurrentImageSource = null; });
            CommandClearAll                  = new RelayCommand(async() => await DoClearAll());
            CommandPickImageFile             = new RelayCommand(async() => await DoPickImageFile());
            CommandApplySampleImageSelection = new RelayCommand(async() => await ApplySampleImageSelection());
            CommandPickRecentColor           = new RelayCommand <SolidColorBrush>(DoPickRecentColor);

            IsFullScreen = false;

            Document = new TracingDocument
            {
                Type   = DocumentType.TempOrNew,
                Status = DocumentStatus.Saved
            };

            RecentColors = new Queue <Color>();
            CurrentCanvasBackgroundBrush = new SolidColorBrush(Colors.White);

            SampleImages = new ObservableCollection <ImageSource>(new List <ImageSource>());
            for (var i = 1; i <= 2; i++)
            {
                SampleImages.Add(new BitmapImage(new Uri($"ms-appx:///Assets/Samples/{i}.jpg")));
            }
        }