private async void ScanWithDefaultSettings() { StorageFolder tempFolder = Windows.Storage.ApplicationData.Current.TemporaryFolder; // Force to use bitmaps in the Flatbed config selectedScanner.FlatbedConfiguration.Format = ImageScannerFormat.DeviceIndependentBitmap; var result = selectedScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Default, tempFolder); }
/// <summary> /// Scans the images from the scanner with auto configured settings /// The scanning is allowed only if the selected scanner supports Device Auto-Configured Scanning. /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the use has already cancelled the scenario if (ModelDataContext.ScenarioRunning) { if (myScanner.IsScanSourceSupported(ImageScannerScanSource.AutoConfigured)) { cancellationToken = new CancellationTokenSource(); // Set the scan file format to PNG, if available if (myScanner.AutoConfiguration.IsFormatSupported(ImageScannerFormat.Png)) { myScanner.AutoConfiguration.Format = ImageScannerFormat.Png; } rootPage.NotifyUser("Scanning", NotifyType.StatusMessage); var progress = new Progress <UInt32>(ScanProgress); // Scan API call to start scanning with Auto-Configured settings var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.AutoConfigured, folder).AsTask(cancellationToken.Token, progress); ModelDataContext.ScenarioRunning = false; if (result.ScannedFiles.Count > 0) { Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage); if (result.ScannedFiles.Count > 1) { Utils.UpdateFileListData(result.ScannedFiles, ModelDataContext); } } else { rootPage.NotifyUser("There were no files scanned.", NotifyType.ErrorMessage); } } else { ModelDataContext.ScenarioRunning = false; rootPage.NotifyUser("The selected scanner does not support Device Auto-Configured Scanning.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, ModelDataContext); } }
/// <summary> /// Scans image from the Flatbed source of the scanner /// The scanning is allowed only if the selected scanner is equipped with a Flatbed /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the user has already canceled the scenario if (ModelDataContext.ScenarioRunning) { if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Flatbed)) { // Set the scan file format to Device Independent Bitmap (DIB) myScanner.FlatbedConfiguration.Format = ImageScannerFormat.DeviceIndependentBitmap; cancellationToken = new CancellationTokenSource(); rootPage.NotifyUser("Scanning", NotifyType.StatusMessage); // Scan API call to start scanning from the Flatbed source of the scanner. var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Flatbed, folder).AsTask(cancellationToken.Token); ModelDataContext.ScenarioRunning = false; if (result.ScannedFiles.Count > 0) { Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage); } else { rootPage.NotifyUser("There are no files scanned from the Flatbed.", NotifyType.ErrorMessage); } } else { ModelDataContext.ScenarioRunning = false; rootPage.NotifyUser("The selected scanner does not report to be equipped with a Flatbed.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, ModelDataContext); } }
/// <summary> /// Scans all the images from Feeder source of the scanner /// The scanning is allowed only if the selected scanner is equipped with a Feeder /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the use has already cancelled the scenario if (model.ScenarioRunning) { if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder)) { // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder myScanner.FeederConfiguration.MaxNumberOfPages = 0; myScanner.FeederConfiguration.Duplex = tggDuplex.IsOn; myScanner.FeederConfiguration.PageSize = (Windows.Graphics.Printing.PrintMediaSize)model.ScannerDataContext.CurrentSize; cancellationToken = new CancellationTokenSource(); rootPage.NotifyUser("Escaneando", NotifyType.StatusMessage); // Scan API call to start scanning from the Feeder source of the scanner. var operation = myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder); operation.Progress = new AsyncOperationProgressHandler <ImageScannerScanResult, uint>(ScanProgress); var result = await operation.AsTask <ImageScannerScanResult, UInt32>(cancellationToken.Token); // Number of scanned files should be zero here since we already processed during scan progress notifications all the files that have been scanned rootPage.NotifyUser("Escaneo completado.", NotifyType.StatusMessage); model.ScenarioRunning = false; } else { model.ScenarioRunning = false; rootPage.NotifyUser("El escáner seleccionado indica no tener Feeder.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException ex) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, model); } }
/// <summary> /// Scans all the images from Feeder source of the scanner /// The scanning is allowed only if the selected scanner is equipped with a Feeder /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the use has already cancelled the scenario if (ModelDataContext.ScenarioRunning) { if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder)) { // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder myScanner.FeederConfiguration.MaxNumberOfPages = 0; cancellationToken = new CancellationTokenSource(); rootPage.NotifyUser("Scanning", NotifyType.StatusMessage); // Scan API call to start scanning from the Feeder source of the scanner. var operation = myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder); operation.Progress = new AsyncOperationProgressHandler <ImageScannerScanResult, uint>(ScanProgress); var result = await operation.AsTask <ImageScannerScanResult, UInt32>(cancellationToken.Token); // Number of scanned files should be zero here since we already processed during scan progress notifications all the files that have been scanned rootPage.NotifyUser("Scanning is complete.", NotifyType.StatusMessage); ModelDataContext.ScenarioRunning = false; } else { ModelDataContext.ScenarioRunning = false; rootPage.NotifyUser("The selected scanner does not report to be equipped with a Feeder.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, ModelDataContext); } }
/// <summary> /// Scans the images from the scanner with default settings /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the use has already cancelled the scenario if (ModelDataContext.ScenarioRunning) { cancellationToken = new CancellationTokenSource(); rootPage.NotifyUser("Scanning", NotifyType.StatusMessage); var progress = new Progress <UInt32>(ScanProgress); // Scan API call to start scanning var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Default, folder).AsTask(cancellationToken.Token, progress); ModelDataContext.ScenarioRunning = false; if (result.ScannedFiles.Count > 0) { Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage); if (result.ScannedFiles.Count > 1) { Utils.UpdateFileListData(result.ScannedFiles, ModelDataContext); } } else { rootPage.NotifyUser("There were no files scanned.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, ModelDataContext); } }
private async void OnScannerAdded(DeviceWatcher sender, DeviceInformation deviceInfo) { await MainPage.Current.Dispatcher.RunAsync( Windows.UI.Core.CoreDispatcherPriority.Normal, () => { string stuff = "test"; //MainPage.Current.NotifyUser(String.Format("Scanner with device id {0} has been added", deviceInfo.Id), NotifyType.StatusMessage); //// search the device list for a device with a matching device id //ScannerDataItem match = FindInList(deviceInfo.Id); //// If we found a match then mark it as verified and return //if (match != null) //{ // match.Matched = true; // return; //} //// Add the new element to the end of the list of devices //AppendToList(deviceInfo); } ); //var library = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures); //var folders = library.Folders; StorageFolder testFolder = await StorageFolder.GetFolderFromPathAsync(@"D:\Pictures\Test"); //ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); //4D36E967-E325-11CE-BFC1-08002BE10318 ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceInfo.Id); var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Default, testFolder); }
/// <summary> /// Scans all the images from Feeder source of the scanner /// The scanning of the image is allowed only if the selected scanner has Feeder source /// </summary> /// <param name="deviceId">scanner device id</param> /// <param name="folder">the folder that receives the scanned files</param> public async void ScanToFolder(string deviceId, StorageFolder folder) { try { // Get the scanner object for this device id ImageScanner myScanner = await ImageScanner.FromIdAsync(deviceId); // Check to see if the use has already cancelled the scenario if (ModelDataContext.ScenarioRunning) { if (myScanner.IsScanSourceSupported(ImageScannerScanSource.Feeder)) { // Update Feeder Configuration // Set the scan file format to PNG, if available, if not to DIB if (myScanner.FeederConfiguration.IsFormatSupported(ImageScannerFormat.Png)) { myScanner.FeederConfiguration.Format = ImageScannerFormat.Png; } else { myScanner.FeederConfiguration.Format = ImageScannerFormat.DeviceIndependentBitmap; } // Set the color mode to Grayscale, if available if (myScanner.FeederConfiguration.IsColorModeSupported(ImageScannerColorMode.Grayscale)) { myScanner.FeederConfiguration.ColorMode = ImageScannerColorMode.Grayscale; } // Set feeder to scan duplex myScanner.FeederConfiguration.Duplex = myScanner.FeederConfiguration.CanScanDuplex; // Set MaxNumberOfPages to zero to scanning all the pages that are present in the feeder myScanner.FeederConfiguration.MaxNumberOfPages = 0; rootPage.NotifyUser("Scanning", NotifyType.StatusMessage); var progress = new Progress <UInt32>(ScanProgress); cancellationToken = new CancellationTokenSource(); // Scan API call to start scanning from the Feeder source of the scanner. var result = await myScanner.ScanFilesToFolderAsync(ImageScannerScanSource.Feeder, folder).AsTask(cancellationToken.Token, progress); ModelDataContext.ScenarioRunning = false; if (result.ScannedFiles.Count > 0) { Utils.DisplayImageAndScanCompleteMessage(result.ScannedFiles, DisplayImage); if (result.ScannedFiles.Count > 1) { Utils.UpdateFileListData(result.ScannedFiles, ModelDataContext); } } else { rootPage.NotifyUser("There are no files scanned from the Feeder.", NotifyType.ErrorMessage); } } else { ModelDataContext.ScenarioRunning = false; rootPage.NotifyUser("The selected scanner does not report to be equipped with a Feeder.", NotifyType.ErrorMessage); } } } catch (OperationCanceledException) { Utils.DisplayScanCancelationMessage(); } catch (Exception ex) { Utils.OnScenarioException(ex, ModelDataContext); } }