public static Item GetItem(Device device, ExtendedScanSettings settings) { Item item; if (settings.UseNativeUI) { try { var items = new CommonDialogClass().ShowSelectItems(device, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality, true, true, true); item = items[1]; } catch (COMException e) { if ((uint)e.ErrorCode == Errors.UI_CANCELED) { return(null); } throw; } } else { item = device.Items[1]; } return(item); }
private bool GetProfile(out ExtendedScanSettings profile) { try { if (options.ProfileName == null) { // If no profile is specified, use the default (if there is one) profile = profileManager.Profiles.Single(x => x.IsDefault); } else { // Use the profile with the specified name (case-sensitive) profile = profileManager.Profiles.FirstOrDefault(x => x.DisplayName == options.ProfileName); if (profile == null) { // If none found, try case-insensitive profile = profileManager.Profiles.First(x => x.DisplayName.ToLower() == options.ProfileName.ToLower()); } } } catch (InvalidOperationException) { errorOutput.DisplayError(ConsoleResources.ProfileUnavailableOrAmbiguous); profile = null; return(false); } return(true); }
public static void Configure(Device device, Item item, ExtendedScanSettings settings) { if (settings.UseNativeUI) { return; } ConfigureDeviceProperties(device, settings); ConfigureItemProperties(device, item, settings); }
public WiaBackgroundEventLoop(ExtendedScanSettings settings, ScanDevice scanDevice) { this.settings = settings; this.scanDevice = scanDevice; thread = new Thread(RunEventLoop); thread.SetApartmentState(ApartmentState.STA); thread.Start(); // Wait for the thread to initialize the background form and event loop initWaiter.WaitOne(); }
private void SaveSettings() { ScanPageSize pageSize; PageDimensions customPageSize = null; if (cmbPage.SelectedIndex > (int)ScanPageSize.Custom) { pageSize = ScanPageSize.Custom; customPageSize = (PageDimensions)cmbPage.SelectedItem; } else if (cmbPage.SelectedIndex == (int)ScanPageSize.Custom) { throw new InvalidOperationException("Custom page size should never be selected when saving"); } else { pageSize = (ScanPageSize)cmbPage.SelectedIndex; } ScanSettings = new ExtendedScanSettings { Version = ExtendedScanSettings.CURRENT_VERSION, Device = CurrentDevice, IsDefault = isDefault, DriverName = DeviceDriverName, DisplayName = txtName.Text, IconID = iconID, MaxQuality = cbHighQuality.Checked, UseNativeUI = rdbNative.Checked, AfterScanScale = (ScanScale)cmbScale.SelectedIndex, BitDepth = (ScanBitDepth)cmbDepth.SelectedIndex, Brightness = trBrightness.Value, Contrast = trContrast.Value, PageAlign = (ScanHorizontalAlign)cmbAlign.SelectedIndex, PageSize = pageSize, CustomPageSize = customPageSize, Resolution = (ScanDpi)cmbResolution.SelectedIndex, PaperSource = (ScanSource)cmbSource.SelectedIndex }; }
private void PerformScan(ExtendedScanSettings profile) { OutputVerbose(ConsoleResources.BeginningScan); IWin32Window parentWindow = new Form { Visible = false }; totalPagesScanned = 0; foreach (int i in Enumerable.Range(1, options.Number)) { if (options.Delay > 0) { OutputVerbose(ConsoleResources.Waiting, options.Delay); Thread.Sleep(options.Delay); } OutputVerbose(ConsoleResources.StartingScan, i, options.Number); pagesScanned = 0; scanPerformer.PerformScan(profile, parentWindow, this); OutputVerbose(ConsoleResources.PagesScanned, pagesScanned); } }
private static void ConfigureDeviceProperties(Device device, ExtendedScanSettings settings) { if (settings.PaperSource != ScanSource.Glass && DeviceSupportsFeeder(device)) { SetDeviceIntProperty(device, 1, DeviceProperties.PAGES); } switch (settings.PaperSource) { case ScanSource.Glass: SetDeviceIntProperty(device, Source.FLATBED, DeviceProperties.PAPER_SOURCE); break; case ScanSource.Feeder: SetDeviceIntProperty(device, Source.FEEDER, DeviceProperties.PAPER_SOURCE); break; case ScanSource.Duplex: SetDeviceIntProperty(device, Source.DUPLEX | Source.FEEDER, DeviceProperties.PAPER_SOURCE); break; } }
private bool GetProfile(out ExtendedScanSettings profile) { try { if (options.ProfileName == null) { // If no profile is specified, use the default (if there is one) profile = profileManager.Profiles[0]; } else { // Use the profile with the specified name (case-sensitive) profile = profileManager.Profiles.FirstOrDefault(x => x.DisplayName == options.ProfileName); if (profile == null) { // If none found, try case-insensitive profile = profileManager.Profiles.First(x => x.DisplayName.ToLower() == options.ProfileName.ToLower()); } } } catch { //errorOutput.DisplayError(ConsoleResources.ProfileUnavailableOrAmbiguous); profile = new ExtendedScanSettings { DisplayName = "sceye TWAIN", DriverName = "twain", Device = new ScanDevice { ID = "sceye TWAIN", Name = "sceye TWAIN", } }; return(true); } return(true); }
private static void ConfigureItemProperties(Device device, Item item, ExtendedScanSettings settings) { switch (settings.BitDepth) { case ScanBitDepth.Grayscale: SetItemIntProperty(item, 2, ItemProperties.DATA_TYPE); break; case ScanBitDepth.C24Bit: SetItemIntProperty(item, 3, ItemProperties.DATA_TYPE); break; case ScanBitDepth.BlackWhite: SetItemIntProperty(item, 0, ItemProperties.DATA_TYPE); break; } int resolution = settings.Resolution.ToIntDpi(); SetItemIntProperty(item, resolution, ItemProperties.VERTICAL_RESOLUTION); SetItemIntProperty(item, resolution, ItemProperties.HORIZONTAL_RESOLUTION); PageDimensions pageDimensions = settings.PageSize.PageDimensions() ?? settings.CustomPageSize; if (pageDimensions == null) { throw new InvalidOperationException("No page size specified"); } int pageWidth = pageDimensions.WidthInThousandthsOfAnInch() * resolution / 1000; int pageHeight = pageDimensions.HeightInThousandthsOfAnInch() * resolution / 1000; int horizontalSize = GetDeviceIntProperty(device, settings.PaperSource == ScanSource.Glass ? DeviceProperties.HORIZONTAL_BED_SIZE : DeviceProperties.HORIZONTAL_FEED_SIZE); int verticalSize = GetDeviceIntProperty(device, settings.PaperSource == ScanSource.Glass ? DeviceProperties.VERTICAL_BED_SIZE : DeviceProperties.VERTICAL_FEED_SIZE); int pagemaxwidth = horizontalSize * resolution / 1000; int pagemaxheight = verticalSize * resolution / 1000; int horizontalPos = 0; if (settings.PageAlign == ScanHorizontalAlign.Center) horizontalPos = (pagemaxwidth - pageWidth) / 2; else if (settings.PageAlign == ScanHorizontalAlign.Left) horizontalPos = (pagemaxwidth - pageWidth); pageWidth = pageWidth < pagemaxwidth ? pageWidth : pagemaxwidth; pageHeight = pageHeight < pagemaxheight ? pageHeight : pagemaxheight; SetItemIntProperty(item, pageWidth, ItemProperties.HORIZONTAL_EXTENT); SetItemIntProperty(item, pageHeight, ItemProperties.VERTICAL_EXTENT); SetItemIntProperty(item, horizontalPos, ItemProperties.HORIZONTAL_START); SetItemIntProperty(item, settings.Contrast, -1000, 1000, ItemProperties.CONTRAST); SetItemIntProperty(item, settings.Brightness, -1000, 1000, ItemProperties.BRIGHTNESS); }
public static Item GetItem(Device device, ExtendedScanSettings settings) { Item item; if (settings.UseNativeUI) { try { var items = new CommonDialogClass().ShowSelectItems(device, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality, true, true, true); item = items[1]; } catch (COMException e) { if ((uint)e.ErrorCode == Errors.UI_CANCELED) return null; throw; } } else { item = device.Items[1]; } return item; }
private static void ConfigureItemProperties(Device device, Item item, ExtendedScanSettings settings) { switch (settings.BitDepth) { case ScanBitDepth.Grayscale: SetItemIntProperty(item, 2, ItemProperties.DATA_TYPE); break; case ScanBitDepth.C24Bit: SetItemIntProperty(item, 3, ItemProperties.DATA_TYPE); break; case ScanBitDepth.BlackWhite: SetItemIntProperty(item, 0, ItemProperties.DATA_TYPE); break; } int resolution = settings.Resolution.ToIntDpi(); SetItemIntProperty(item, resolution, ItemProperties.VERTICAL_RESOLUTION); SetItemIntProperty(item, resolution, ItemProperties.HORIZONTAL_RESOLUTION); PageDimensions pageDimensions = settings.PageSize.PageDimensions() ?? settings.CustomPageSize; if (pageDimensions == null) { throw new InvalidOperationException("No page size specified"); } int pageWidth = pageDimensions.WidthInThousandthsOfAnInch() * resolution / 1000; int pageHeight = pageDimensions.HeightInThousandthsOfAnInch() * resolution / 1000; int horizontalSize = GetDeviceIntProperty(device, settings.PaperSource == ScanSource.Glass ? DeviceProperties.HORIZONTAL_BED_SIZE : DeviceProperties.HORIZONTAL_FEED_SIZE); int verticalSize = GetDeviceIntProperty(device, settings.PaperSource == ScanSource.Glass ? DeviceProperties.VERTICAL_BED_SIZE : DeviceProperties.VERTICAL_FEED_SIZE); int pagemaxwidth = horizontalSize * resolution / 1000; int pagemaxheight = verticalSize * resolution / 1000; int horizontalPos = 0; if (settings.PageAlign == ScanHorizontalAlign.Center) { horizontalPos = (pagemaxwidth - pageWidth) / 2; } else if (settings.PageAlign == ScanHorizontalAlign.Left) { horizontalPos = (pagemaxwidth - pageWidth); } pageWidth = pageWidth < pagemaxwidth ? pageWidth : pagemaxwidth; pageHeight = pageHeight < pagemaxheight ? pageHeight : pagemaxheight; SetItemIntProperty(item, pageWidth, ItemProperties.HORIZONTAL_EXTENT); SetItemIntProperty(item, pageHeight, ItemProperties.VERTICAL_EXTENT); SetItemIntProperty(item, horizontalPos, ItemProperties.HORIZONTAL_START); SetItemIntProperty(item, settings.Contrast, -1000, 1000, ItemProperties.CONTRAST); SetItemIntProperty(item, settings.Brightness, -1000, 1000, ItemProperties.BRIGHTNESS); }
public static void Configure(Device device, Item item, ExtendedScanSettings settings) { ConfigureDeviceProperties(device, settings); ConfigureItemProperties(device, item, settings); }