// method to do the actual scanning public void Scan() { var scanner = new ScannerService(); try { ImageFile file = scanner.Scan(); if (file != null) { var converter = new ScannerImageConverter(); ScannedImage = converter.ConvertScannedImage(file); } else { ScannedImage = null; } } catch (ScannerException ex) { // yeah, I know. Showing UI from the VM. Shoot me now. MessageBox.Show(ex.Message, "Unable to Scan Image"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } }
// method to do the actual scanning public void Scan() { StatusText = "Сканирование..."; var scanner = new ScannerService(); try { ImageFile file = scanner.Scan(); if (file != null) { var converter = new ScannerImageConverter(); _image = converter.ConvertScannedImage(file); } else { _image = null; } ImageBrush = new ImageBrush(_image) { Stretch = Stretch.Uniform }; } catch (ScannerException ex) { // yeah, I know. Showing UI from the VM. Shoot me now. MessageBox.Show(ex.Message, "Не удалось выполнить сканирование изображения", MessageBoxButton.OK, MessageBoxImage.Warning); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error); } StatusText = "Готово."; }
public void Scan() { var scanner = new ScannerService(); scanner.NativeUI = (bool)NativeUICeckBox.IsChecked; scanner.BitDepth = setBitDepths(); try { //WiaImageIntent.ColorIntent, NativeUICeckBox.IsChecked ImageFile file = scanner.Scan(); if (file != null) { var converter = new ScannerImageConverter(); //ScannedImage = converter.ConvertScannedImage(file); ScannedImage = converter.InMemoryConvertScannedImage(file); } else { ScannedImage = null; } } catch (ScannerException ex) { MessageBox.Show(ex.Message, "Problem z skanowaniem obrazu!"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Błąd!"); } }
public async void Scan() { _model.VisibilityHeader = Visibility.Hidden; var pAsync = await activeWindow.ShowProgressAsync("Status", "Starting...", false, s_without_animation); pAsync.SetIndeterminate(); await Task.Delay(500); var scanner = new ScannerService(); activeWindow.FindChild <WebBrowser>("pdfview").Navigate("about:blank"); if (File.Exists($"{_model.TempFolder}Preview.pdf")) { AcrobatProcess(); await Task.Delay(500); File.Delete($"{_model.TempFolder}Preview.pdf"); } var file = await Task <ImageFile> .Factory.StartNew(() => scanner.Scan(pAsync, _model.ColorSetting)).ContinueWith(async(t) => { try { if (t != null) { var converter = new ScannerImageConverter(_model.TempFolder); _model.OpenedFileName = "Preview"; _model.FileNameToSave = _model.OpenedFileName; _model.OpenedFileFolder = _model.TempFolder; _model.ScannedImage = converter.ConvertScannedImage(t.Result); var saveResult = converter.SaveOnPDF(_model.ScannedImage as BitmapFrame, pAsync); _model.FullPathOpenedFile = $@"{_model.TempFolder}{_model.OpenedFileName}"; await pAsync.CloseAsync(); _model.SaveAsEnable = true; _model.VisibilityHeader = Visibility.Visible; App.Current.Dispatcher.Invoke(() => { activeWindow.FindChild <WebBrowser>("pdfview").Navigate($"{_model.FullPathOpenedFile}.pdf"); }); } else { _model.ScannedImage = null; _model.SaveAsEnable = false; } } catch (Exception ex) { ControlsErrorState(); await pAsync.CloseAsync(); ShowErrorMessage(message: ex.Message); _model.ScannedImage = null; _model.VisibilityHeader = (string.IsNullOrWhiteSpace(_model.OpenedFileName)) ? Visibility.Hidden : Visibility.Visible; } }); }
public void digitalizar() { var scanner = new ScannerService(); try { ImageFile file = scanner.Scan(); if (file != null) { var converter = new ScannerImageConverter(); converter.ConvertScannedImage(file); uriImagem = converter.fileName; } else { uriImagem = null; } } catch (Exception ex) { throw ex; } }
public async void ShowAddingPage() { if (_model.PDF2Add == null || _model.DestinationFile == null) { return; } if (_model.PDF2Add.Where(w => w.Check2Add != false).Select(w => w).Count() == 0) { return; } var x = await activeWindow.ShowProgressAsync("Starting to Add Pages", "", false, s_without_animation); var converter = new ScannerImageConverter(_model.TempFolder); _model.IsMsgVisible = true; try { var pass = string.Empty; AcrobatProcess(); await Task.Delay(500); foreach (var item in _model.PDF2Add) { try { if (item.Check2Add != false) { await Task.Factory.StartNew(() => converter.AddToExistingPDF(item.FullPathWithExtension, $@"{_model.TempFolder}{_model.DestinationFile.FullName}.pdf", x)); } } catch (Exception ex) { //if (ex.Message.ToUpper() == "A PASSWORD IS REQUIRED TO OPEN THE PDF DOCUMENT.") // pass = await AskForPassword(item.FullName); if (ex.Message.ToUpper() == "THE SPECIFIED PASSWORD IS INVALID.") { pass = await AskForPassword(item.FullName); if (pass != null) { try { await Task.Factory.StartNew(() => converter.AddToExistingPDF(item.FullPathWithExtension, $@"{_model.TempFolder}{_model.DestinationFile.FullName}.pdf", x, pass)); } catch (Exception exx) { await ShowErrorMessage($"File: {item.FullName}.pdf", exx.Message); } } } else { await ShowErrorMessage(message : ex.Message); } } } await x.CloseAsync(); _model.IsMsgVisible = false; } catch (Exception ex) { await x.CloseAsync(); await ShowErrorMessage(message : ex.Message); _model.IsMsgVisible = false; } activeWindow.FindChild <WebBrowser>("pdfview").Navigate($"{_model.TempFolder}{_model.DestinationFile.FullName}.pdf"); }
public async void ShowScanAndAdd() { _model.IsMsgVisible = true; var scanner = new ScannerService(); var pAsync = await activeWindow.ShowProgressAsync("Status", "Starting...", false, s_without_animation); pAsync.SetIndeterminate(); var converter = new ScannerImageConverter(_model.TempFolder); switch (_model.AutoAdd) { case true: await Task.Factory.StartNew(async() => { try { var filee = scanner.ScanAll(pAsync, _model.ColorSetting); if (filee.Count == 0) { await pAsync.CloseAsync(); return; } converter.SavePDFsOn(filee, pAsync); await pAsync.CloseAsync(); _model.IsMsgVisible = false; AcrobatProcess(); await Task.Delay(500); pAsync.SetMessage("Adding pages to file..."); await Task.Factory.StartNew(() => converter.AddToExistingPDF($@"{_model.TempFolder}Preview.pdf", $@"{_model.TempFolder}{_model.FileNameAdded}.pdf")); App.Current.Dispatcher.Invoke(() => { activeWindow.FindChild <WebBrowser>("pdfview").Navigate($@"{_model.TempFolder}{_model.FileNameAdded}.pdf"); }); await pAsync.CloseAsync(); _model.IsMsgVisible = false; } catch (Exception ex) { await pAsync.CloseAsync(); App.Current.Dispatcher.Invoke(() => { ShowErrorMessage(ex.Message); }); } }); break; case false: var file = await Task <ImageFile> .Factory.StartNew(() => scanner.Scan(pAsync, _model.ColorSetting)).ContinueWith(async(t) => { try { if (t != null) { var scannedImage = converter.ConvertScannedImage(t.Result); var saveResult = converter.SaveOnPDF(scannedImage as BitmapFrame, pAsync); AcrobatProcess(); await Task.Delay(500); pAsync.SetMessage("Adding pages to file..."); await Task.Factory.StartNew(() => converter.AddToExistingPDF($@"{_model.TempFolder}Preview.pdf", $@"{_model.TempFolder}{_model.FileNameAdded}.pdf")); App.Current.Dispatcher.Invoke(() => { activeWindow.FindChild <WebBrowser>("pdfview").Navigate($@"{_model.TempFolder}{_model.FileNameAdded}.pdf"); }); await pAsync.CloseAsync(); _model.IsMsgVisible = false; } else { } } catch (Exception ex) { await pAsync.CloseAsync(); App.Current.Dispatcher.Invoke(() => { ShowErrorMessage(ex.Message); }); } }); break; default: break; } // _model.IsMsgVisible = false; }
public async void ShowScanAll() { _model.VisibilityHeader = Visibility.Hidden; var pAsync = await activeWindow.ShowProgressAsync("Status", "Scanning...", false, s_without_animation); pAsync.SetIndeterminate(); await Task.Delay(500); if (File.Exists($"{_model.TempFolder}Preview.pdf")) { activeWindow.FindChild <WebBrowser>("pdfview").Navigate("about:blank"); AcrobatProcess(); await Task.Delay(500); File.Delete($"{_model.TempFolder}Preview.pdf"); } var scanner = new ScannerService(); var converter = new ScannerImageConverter(_model.TempFolder); await Task.Factory.StartNew(async() => { try { var file = scanner.ScanAll(pAsync, _model.ColorSetting); if (file.Count == 0) { await pAsync.CloseAsync(); return; } _model.ScannedImage = null; _model.OpenedFileName = "Preview"; _model.FileNameToSave = _model.OpenedFileName; _model.OpenedFileFolder = _model.TempFolder; converter.SavePDFsOn(file, pAsync); if (File.Exists($@"{_model.TempFolder}{_model.OpenedFileName}.pdf")) { _model.FullPathOpenedFile = $@"{_model.TempFolder}{_model.OpenedFileName}"; } else { return; } } catch (Exception ex) { ControlsErrorState(); await pAsync.CloseAsync(); ShowErrorMessage(message: ex.Message); _model.ScannedImage = null; } }); if (File.Exists($@"{_model.FullPathOpenedFile}.pdf")) { activeWindow.FindChild <WebBrowser>("pdfview").Navigate($"{_model.FullPathOpenedFile}.pdf"); _model.SaveAsEnable = true; } else { return; } await pAsync.CloseAsync(); _model.VisibilityHeader = Visibility.Visible; }