Exemplo n.º 1
0
 public void NegotiateFeeder(ScanSettings scanSettings)
 {
     if (scanSettings.UseDocumentFeeder.HasValue)
     {
         Capability.SetCapability(Capabilities.FeederEnabled, scanSettings.UseDocumentFeeder.Value, _applicationId, SourceId);
     }
     if (scanSettings.UseAutoFeeder.HasValue)
     {
         Capability.SetCapability(Capabilities.AutoFeed, scanSettings.UseAutoFeeder == true && scanSettings.UseDocumentFeeder == true, _applicationId, SourceId);
     }
     if (scanSettings.UseAutoScanCache.HasValue)
     {
         Capability.SetCapability(Capabilities.AutoScan, scanSettings.UseAutoScanCache.Value, _applicationId, SourceId);
     }
 }
Exemplo n.º 2
0
        public short GetBitDepth(ScanSettings scanSettings)
        {
            switch (scanSettings.Resolution.ColourSetting)
            {
            case ColourSetting.BlackAndWhite:
                return(1);

            case ColourSetting.GreyScale:
                return(8);

            case ColourSetting.Colour:
                return(16);
            }

            throw new NotImplementedException();
        }
Exemplo n.º 3
0
        public PixelType GetPixelType(ScanSettings scanSettings)
        {
            switch (scanSettings.Resolution.ColourSetting)
            {
            case ColourSetting.BlackAndWhite:
                return(PixelType.BlackAndWhite);

            case ColourSetting.GreyScale:
                return(PixelType.Grey);

            case ColourSetting.Colour:
                return(PixelType.Rgb);
            }

            throw new NotImplementedException();
        }
Exemplo n.º 4
0
        private bool NegotiateArea(ScanSettings scanSettings)
        {
            var area = scanSettings.Area;

            if (area == null)
            {
                return(false);
            }

            var cap = new Capability(Capabilities.IUnits, TwainType.Int16, _applicationId, SourceId);

            if ((Units)cap.GetBasicValue().Int16Value != area.Units)
            {
                Capability.SetCapability(Capabilities.IUnits, (short)area.Units, _applicationId, SourceId);
            }

            var imageLayout = new ImageLayout
            {
                Frame = new Frame
                {
                    Left   = new Fix32(area.Left),
                    Top    = new Fix32(area.Top),
                    Right  = new Fix32(area.Right),
                    Bottom = new Fix32(area.Bottom)
                }
            };

            var result = Twain32Native.DsImageLayout(
                _applicationId,
                SourceId,
                DataGroup.Image,
                DataArgumentType.ImageLayout,
                Message.Set,
                imageLayout);

            if (result != TwainResult.Success)
            {
                throw new TwainException("DsImageLayout.GetDefault error", result);
            }

            return(true);
        }
Exemplo n.º 5
0
        public bool Open(ScanSettings settings)
        {
            OpenSource();

            if (settings.AbortWhenNoPaperDetectable && !PaperDetectable)
            {
                throw new FeederEmptyException();
            }

            // Set whether or not to show progress window
            NegotiateProgressIndicator(settings);
            NegotiateTransferCount(settings);
            NegotiateFeeder(settings);
            NegotiateDuplex(settings);

            if (settings.UseDocumentFeeder == true &&
                settings.Page != null)
            {
                NegotiatePageSize(settings);
                NegotiateOrientation(settings);
            }

            if (settings.Resolution != null)
            {
                NegotiateColour(settings);
                NegotiateResolution(settings);
            }

            if (settings.Area != null)
            {
                NegotiateArea(settings);
            }

            // Configure automatic rotation and image border detection
            if (settings.Rotation != null)
            {
                NegotiateAutomaticRotate(settings);
                NegotiateAutomaticBorderDetection(settings);
            }

            return(Enable(settings));
        }
Exemplo n.º 6
0
        public bool Enable(ScanSettings settings)
        {
            UserInterface ui = new UserInterface();

            ui.ShowUI     = (short)(settings.ShowTwainUI ? 1 : 0);
            ui.ModalUI    = 1;
            ui.ParentHand = _messageHook.WindowHandle;

            var result = Twain32Native.DsUserInterface(
                _applicationId,
                SourceId,
                DataGroup.Control,
                DataArgumentType.UserInterface,
                Message.EnableDS,
                ui);

            if (result != TwainResult.Success)
            {
                Dispose();
                return(false);
            }
            return(true);
        }
Exemplo n.º 7
0
        public void StartScan(ScanSettings settings)
        {
            bool scanning = false;

            try
            {
                _messageHook.UseFilter = true;
                scanning = DataSource.Open(settings);
            }
            catch (TwainException e)
            {
                DataSource.Close();
                EndingScan();
                throw e;
            }
            finally
            {
                // Remove the message hook if scan setup failed
                if (!scanning)
                {
                    EndingScan();
                }
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Starts scanning.
 /// </summary>
 public void StartScanning(ScanSettings settings)
 {
     _dataSourceManager.StartScan(settings);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Starts scanning.
 /// </summary>
 public void StartScanning(ScanSettings settings)
 {
     _dataSourceManager.StartScan(settings);
 }
Exemplo n.º 10
0
        private bool NegotiateArea(ScanSettings scanSettings)
        {
            var area = scanSettings.Area;

            if (area == null)
            {
                return false;
            }

            var cap = new Capability(Capabilities.IUnits, TwainType.Int16, _applicationId, SourceId);
            if ((Units)cap.GetBasicValue().Int16Value != area.Units)
            {
                Capability.SetCapability(Capabilities.IUnits, (short)area.Units, _applicationId, SourceId);
            }

            var imageLayout = new ImageLayout
            {
                Frame = new Frame
                {
                    Left = new Fix32(area.Left),
                    Top = new Fix32(area.Top),
                    Right = new Fix32(area.Right),
                    Bottom = new Fix32(area.Bottom)
                }
            };

            var result = Twain32Native.DsImageLayout(
                _applicationId,
                SourceId,
                DataGroup.Image,
                DataArgumentType.ImageLayout,
                Message.Set,
                imageLayout);

            if (result != TwainResult.Success)
            {
                throw new TwainException("DsImageLayout.GetDefault error", result);
            }

            return true;
        }
Exemplo n.º 11
0
        public bool Open(ScanSettings settings)
        {
            OpenSource();

            if (settings.AbortWhenNoPaperDetectable && !PaperDetectable)
                throw new FeederEmptyException();

            // Set whether or not to show progress window
            NegotiateProgressIndicator(settings);
            NegotiateTransferCount(settings);
            NegotiateFeeder(settings);
            NegotiateDuplex(settings);

            if (settings.UseDocumentFeeder == true &&
                settings.Page != null)
            {
                NegotiatePageSize(settings);
                NegotiateOrientation(settings);
            }

            if (settings.Resolution != null)
            {
                NegotiateColour(settings);
                NegotiateResolution(settings);
            }

            if (settings.Area != null)
            {
                NegotiateArea(settings);
            }

            // Configure automatic rotation and image border detection
            if (settings.Rotation != null)
            {
                NegotiateAutomaticRotate(settings);
                NegotiateAutomaticBorderDetection(settings);
            }

            return Enable(settings);
        }
Exemplo n.º 12
0
 /// <summary>
 /// Negotiates the automatic border detection capability.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiateAutomaticBorderDetection(ScanSettings scanSettings)
 {
     RotationSettings rotationSettings = scanSettings.Rotation;
     Capability.SetCapability(Capabilities.Automaticborderdetection, rotationSettings.AutomaticBorderDetection, _applicationId, SourceId);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Negotiates the indicator.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiateProgressIndicator(ScanSettings scanSettings)
 {
     if (scanSettings.ShowProgressIndicatorUI.HasValue)
     {
         Capability.SetCapability(Capabilities.Indicators, scanSettings.ShowProgressIndicatorUI.Value, _applicationId, SourceId);
     }
 }
Exemplo n.º 14
0
 /// <summary>
 /// Negotiates the size of the page.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiatePageSize(ScanSettings scanSettings)
 {
     var cap = new Capability(Capabilities.Supportedsizes, TwainType.Int16, _applicationId, SourceId);
     if ((PageType)cap.GetBasicValue().Int16Value != PageType.UsLetter)
     {
         Capability.SetBasicCapability(Capabilities.Supportedsizes, (ushort)scanSettings.Page.Size, TwainType.UInt16, _applicationId, SourceId);
     }
 }
Exemplo n.º 15
0
 public void NegotiateOrientation(ScanSettings scanSettings)
 {
     // Set orientation (default is portrait)
     var cap = new Capability(Capabilities.Orientation, TwainType.Int16, _applicationId, SourceId);
     if ((Orientation)cap.GetBasicValue().Int16Value != Orientation.Default)
     {
         Capability.SetBasicCapability(Capabilities.Orientation, (ushort)scanSettings.Page.Orientation, TwainType.UInt16, _applicationId, SourceId);
     }
 }
Exemplo n.º 16
0
 public void NegotiateFeeder(ScanSettings scanSettings)
 {
     if (scanSettings.UseDocumentFeeder.HasValue)
     {
         Capability.SetCapability(Capabilities.FeederEnabled, scanSettings.UseDocumentFeeder.Value, _applicationId, SourceId);
     }
     if (scanSettings.UseAutoFeeder.HasValue)
     {
         Capability.SetCapability(Capabilities.AutoFeed, scanSettings.UseAutoFeeder == true && scanSettings.UseDocumentFeeder == true, _applicationId, SourceId);
     }
     if (scanSettings.UseAutoScanCache.HasValue)
     {
         Capability.SetCapability(Capabilities.AutoScan, scanSettings.UseAutoScanCache.Value, _applicationId, SourceId);
     }
 }
Exemplo n.º 17
0
 public void NegotiateDuplex(ScanSettings scanSettings)
 {
     if (scanSettings.UseDuplex.HasValue && SupportsDuplex)
     {
         Capability.SetCapability(Capabilities.DuplexEnabled, scanSettings.UseDuplex.Value, _applicationId, SourceId);
     }
 }
Exemplo n.º 18
0
        public void NegotiateColour(ScanSettings scanSettings)
        {
            Capability.SetBasicCapability(Capabilities.IPixelType, (ushort)GetPixelType(scanSettings), TwainType.UInt16, _applicationId, SourceId);

            // TODO: Also set this for colour scanning
            if (scanSettings.Resolution.ColourSetting != ColourSetting.Colour)
            {
                Capability.SetCapability(Capabilities.BitDepth, GetBitDepth(scanSettings), _applicationId, SourceId);
            }
        }
Exemplo n.º 19
0
 /// <summary>
 /// Negotiates the automatic rotation capability.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiateAutomaticRotate(ScanSettings scanSettings)
 {
     RotationSettings rotationSettings = scanSettings.Rotation;
     Capability.SetCapability(Capabilities.Automaticrotate, rotationSettings.AutomaticRotate, _applicationId, SourceId);
 }
Exemplo n.º 20
0
        /// <summary>
        /// Negotiates the automatic rotation capability.
        /// </summary>
        /// <param name="scanSettings">The scan settings.</param>
        public void NegotiateAutomaticRotate(ScanSettings scanSettings)
        {
            RotationSettings rotationSettings = scanSettings.Rotation;

            Capability.SetCapability(Capabilities.Automaticrotate, rotationSettings.AutomaticRotate, _applicationId, SourceId);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Negotiates the automatic border detection capability.
        /// </summary>
        /// <param name="scanSettings">The scan settings.</param>
        public void NegotiateAutomaticBorderDetection(ScanSettings scanSettings)
        {
            RotationSettings rotationSettings = scanSettings.Rotation;

            Capability.SetCapability(Capabilities.Automaticborderdetection, rotationSettings.AutomaticBorderDetection, _applicationId, SourceId);
        }
Exemplo n.º 22
0
        public short GetBitDepth(ScanSettings scanSettings)
        {
            switch (scanSettings.Resolution.ColourSetting)
            {
                case ColourSetting.BlackAndWhite:
                    return 1;

                case ColourSetting.GreyScale:
                    return 8;

                case ColourSetting.Colour:
                    return 16;
            }

            throw new NotImplementedException();
        }
Exemplo n.º 23
0
        public void StartScan(ScanSettings settings)
        {
            bool scanning = false;

            try
            {
                _messageHook.UseFilter = true;
                scanning = DataSource.Open(settings);
            }
            catch (TwainException e)
            {
                DataSource.Close();
                EndingScan();
                throw e;
            }
            finally
            {
                // Remove the message hook if scan setup failed
                if (!scanning)
                {
                    EndingScan();
                }
            }
        }
Exemplo n.º 24
0
        public PixelType GetPixelType(ScanSettings scanSettings)
        {
            switch (scanSettings.Resolution.ColourSetting)
            {
                case ColourSetting.BlackAndWhite:
                    return PixelType.BlackAndWhite;

                case ColourSetting.GreyScale:
                    return PixelType.Grey;

                case ColourSetting.Colour:
                    return PixelType.Rgb;
            }

            throw new NotImplementedException();
        }
Exemplo n.º 25
0
 public void NegotiateResolution(ScanSettings scanSettings)
 {
     if (scanSettings.Resolution.Dpi.HasValue)
     {
         int dpi = scanSettings.Resolution.Dpi.Value;
         Capability.SetBasicCapability(Capabilities.XResolution, dpi, TwainType.Fix32, _applicationId, SourceId);
         Capability.SetBasicCapability(Capabilities.YResolution, dpi, TwainType.Fix32, _applicationId, SourceId);
     }
 }
Exemplo n.º 26
0
        public bool Enable(ScanSettings settings)
        {
            UserInterface ui = new UserInterface();
            ui.ShowUI = (short)(settings.ShowTwainUI ? 1 : 0);
            ui.ModalUI = 1;
            ui.ParentHand = _messageHook.WindowHandle;

            var result = Twain32Native.DsUserInterface(
                _applicationId,
                SourceId,
                DataGroup.Control,
                DataArgumentType.UserInterface,
                Message.EnableDS,
                ui);

            if (result != TwainResult.Success)
            {
                Dispose();
                return false;
            }
            return true;
        }
Exemplo n.º 27
0
 public void NegotiateTransferCount(ScanSettings scanSettings)
 {
     scanSettings.TransferCount = Capability.SetCapability(
         Capabilities.XferCount,
         scanSettings.TransferCount,
         _applicationId,
         SourceId);
 }
        private void scanButton_Click(object sender, RoutedEventArgs e)
        {
            IsEnabled = false;

            _settings = new ScanSettings()
            {
                UseDocumentFeeder = useAdfCheckBox.IsChecked == true,
                ShowTwainUI = useTwainUICheckBox.IsChecked == true
            };

            try
            {
                if (SourceUserSelected.IsChecked == true)
                {
                    _twain.SelectSource(ManualSource.SelectedItem.ToString());
                }

                _twain.StartScanning(_settings);
            }
            catch (TwainException ex)
            {
                MessageBox.Show(ex.Message);
            }

            IsEnabled = true;
        }