public List<Image> Scan(SettingsAcquire settings) { Log("Scan start"); _images = new List<Image>(); _scanCompleteEvent.Reset(); var scanSettings = new ScanSettings { Resolution = new ResolutionSettings { Dpi = (int) settings.Resolution, ColourSetting = (ColourSetting)settings.PixelType }, Area = new AreaSettings(Units.Inches, 0, 0, settings.Format.Height, settings.Format.Width), ShowProgressIndicatorUI = false, ShowTwainUI = false, UseDocumentFeeder = settings.ScanSource.HasValue && ((ScanFeed)settings.ScanSource.Value == ScanFeed.Feeder || (ScanFeed)settings.ScanSource.Value == ScanFeed.Duplex), UseAutoFeeder = false, UseAutoScanCache = false, UseDuplex = settings.ScanSource.HasValue && (ScanFeed)settings.ScanSource.Value == ScanFeed.Duplex, }; var scan = new StartScan(StartTwainScan); _windowsMessageLoop.Invoke(scan, new object[] { scanSettings }); _scanCompleteEvent.WaitOne(); Log("Scan complete, images count: " + _images.Count); return _images; }
public List<Image> Scan(SettingsAcquire settings) { if (!_twain32.OpenSM()) { throw new Exception("Возникла непредвиденная ошибка, пожалуйста перезапустите TWAIN@Web"); } _twain32.MyAcquire(settings); if (_twain32.Images == null) return null; var images = new List<Image>(); foreach (var image in _twain32.Images) { images.Add(image); } return images; }
public List <Image> Scan(SettingsAcquire settings) { if (!_twain32.OpenSM()) { throw new Exception("Возникла непредвиденная ошибка, пожалуйста перезапустите " + Settings.Default.ServiceName); } _twain32.MyAcquire(settings); if (_twain32.Images == null) { return(null); } var images = new List <Image>(); foreach (var image in _twain32.Images) { images.Add(image); } return(images); }
private void SetAcquireSettings(Device device, SettingsAcquire settings) { Log("Set acquire settings"); var source = device.Items[1]; if (source == null) throw new Exception("Current sourse not found"); SetProperty(source.Properties, WiaProperty.HorizontalResolution, (int)settings.Resolution); SetProperty(source.Properties, WiaProperty.VerticalResolution, (int)settings.Resolution); var horizontalExtent = (int)(settings.Format.Width * settings.Resolution); var verticalExtent = (int)(settings.Format.Height * settings.Resolution); var horizontalExtentMax = FindProperty(source.Properties, WiaProperty.HorizontalExtent).SubTypeMax; var verticalExtentMax = FindProperty(source.Properties, WiaProperty.VerticalExtent).SubTypeMax; var currentIntent = (WiaPixelType)settings.PixelType; SetProperty(source.Properties, WiaProperty.HorizontalExtent, horizontalExtent < horizontalExtentMax ? horizontalExtent : horizontalExtentMax); SetProperty(source.Properties, WiaProperty.VerticalExtent, verticalExtent < verticalExtentMax ? verticalExtent : verticalExtentMax); SetProperty(source.Properties, WiaProperty.CurrentIntent, currentIntent); if (currentIntent == WiaPixelType.Color) try { SetProperty(source.Properties, WiaProperty.BitsPerPixel, 24); } catch (Exception) { } if (settings.ScanSource.HasValue && IsDocumentHandlingSelectSupported(device)) { var documentHandlingSelect = (int)WIA_DPS_DOCUMENT_HANDLING_SELECT.Flatbad; switch ((ScanFeed)settings.ScanSource.Value) { case ScanFeed.Feeder: documentHandlingSelect = (int)WIA_DPS_DOCUMENT_HANDLING_SELECT.Feeder; break; case ScanFeed.Flatbad: documentHandlingSelect = (int)WIA_DPS_DOCUMENT_HANDLING_SELECT.Flatbad; break; case ScanFeed.Duplex: documentHandlingSelect = (int)WIA_DPS_DOCUMENT_HANDLING_SELECT.Duplex | (int)WIA_DPS_DOCUMENT_HANDLING_SELECT.Feeder; break; } SetProperty(device.Properties, WiaProperty.DocumentHandlingSelect, documentHandlingSelect); } Log("Set acquire settings success"); }
/// <summary> /// Use scanner to scan an image (with user selecting the scanner from a dialog). /// </summary> /// <returns>Scanned images.</returns> public List<Image> Scan(SettingsAcquire settings) { if (_deviceId == null) { throw new Exception("Не выбран источник данных для сканера."); } var device = ConnectToDevice(); SetAcquireSettings(device, settings); return Scan(device); }
public ScanResult Execute(object markerAsynchrone) { _log.Info("======================================= SCAN COMMAND ========================================"); _log.Info(string.Format("Start execute with scan params: " + "source={0}, sourceFeed={1}, dpi={2}, colorMode={3}, compressionFormat={4}, format={5}, " + "isPackage={6}, saveAs={7}", _command.Source, _command.DocumentHandlingCap, _command.DPI, _command.ColorMode, _command.CompressionFormat.ImgFormat, _command.Format.Name, _command.IsPackage, _command.SaveAs)); ScanResult scanResult; try { var scannedImages = new List<Image>(); lock (markerAsynchrone) { if (_scannerManager.CurrentSourceIndex != _command.Source) { new AsyncWorker<int>().RunWorkAsync(_command.Source, _scannerManager.ChangeSource, WaitTimeForChangeSource); if (_scannerManager.CurrentSourceIndex != _command.Source) { return new SingleScanResult("Не удается изменить источник данных"); } } var settingAcquire = new SettingsAcquire { Format = _command.Format, Resolution = _command.DPI, PixelType = _command.ColorMode, ScanSource = _command.DocumentHandlingCap }; var images = new AsyncWorker<SettingsAcquire, List<Image>>().RunWorkAsync(settingAcquire, _scannerManager.CurrentSource.Scan, WaitTimaeForScan); if (images != null) { foreach (var image in images) { var clonedImage = (Image) image.Clone(); image.Dispose(); ((Bitmap) clonedImage).SetResolution(_command.DPI, _command.DPI); scannedImages.Add(clonedImage); } } } if (scannedImages.Count == 0) { return new SingleScanResult( "Сканирование завершилось неудачей! Попробуйте переподключить сканер либо повторить сканирование с помощью другого устройства."); } if (scannedImages.Count == 1) { var image = scannedImages[0]; var downloadFile = SaveImage(image); var singleScanResult = new SingleScanResult(); singleScanResult.FillContent(downloadFile); scanResult = singleScanResult; image.Dispose(); } else { var downloadFiles = new List<DownloadFile>(); int counter; try { counter = int.Parse(_command.FileCounter); } catch (Exception) { counter = 1; } foreach (var scannedImage in scannedImages) { var downloadFile = SaveImage(scannedImage, counter++); downloadFiles.Add(downloadFile); scannedImage.Dispose(); } var multipleScanResult = new MultipleScanResult(); multipleScanResult.FillContent(downloadFiles); scanResult = multipleScanResult; } } catch (TwainException ex) { return new SingleScanResult(ex.Message); } _log.Info("Scan command executed"); return scanResult; }