Exemplo n.º 1
0
 /// <summary>
 /// Negotiates the indicator.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiateProgressIndicator(ScanSettings scanSettings)
 {
     try
     {
         if (scanSettings.ShowProgressIndicatorUi.HasValue)
         {
             Capability.SetCapability(Capabilities.Indicators, scanSettings.ShowProgressIndicatorUi.Value, _applicationId, SourceId);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Negotiates the automatic border detection capability.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiateAutomaticBorderDetection(ScanSettings scanSettings)
 {
     try
     {
         if (scanSettings.Rotation.AutomaticBorderDetection)
         {
             Capability.SetCapability(Capabilities.Automaticborderdetection, true, _applicationId, SourceId);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 3
0
 public void NegotiateDuplex(ScanSettings scanSettings)
 {
     try
     {
         if (scanSettings.UseDuplex.HasValue && SupportsDuplex)
         {
             Capability.SetCapability(Capabilities.DuplexEnabled, scanSettings.UseDuplex.Value, _applicationId, SourceId);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 4
0
 public void NegotiateTransferCount(ScanSettings scanSettings)
 {
     try
     {
         scanSettings.TransferCount = Capability.SetCapability(
             Capabilities.XferCount,
             scanSettings.TransferCount,
             _applicationId,
             SourceId);
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Negotiates the size of the page.
 /// </summary>
 /// <param name="scanSettings">The scan settings.</param>
 public void NegotiatePageSize(ScanSettings scanSettings)
 {
     try
     {
         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);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 6
0
        private bool NegotiateArea(ScanSettings scanSettings)
        {
            var area = scanSettings.Area;

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

            try
            {
                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);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }

            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.º 7
0
 public void NegotiateOrientation(ScanSettings scanSettings)
 {
     // Set orientation (default is portrait)
     try
     {
         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);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 8
0
 public void NegotiateResolution(ScanSettings scanSettings)
 {
     try
     {
         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);
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 9
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.º 10
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.º 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);
            NegotiateLightPath(settings);

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

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

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

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

            return(Enable(settings));
        }
Exemplo n.º 12
0
 public void NegotiateLightPath(ScanSettings scanSettings)
 {
     try
     {
         if (scanSettings.UseFilmScanner.HasValue && SupportsFilmScanner)
         {
             if (scanSettings.UseFilmScanner.Value == true)
             {
                 Capability.SetBasicCapability(Capabilities.Lightpath, (ushort)Lightpath.Transmissive, TwainType.UInt16, _applicationId, SourceId);
             }
             else
             {
                 Capability.SetBasicCapability(Capabilities.Lightpath, (ushort)Lightpath.Reflective, TwainType.UInt16, _applicationId, SourceId);
             }
         }
     }
     catch
     {
         // Do nothing if the data source does not support the requested capability
     }
 }
Exemplo n.º 13
0
        public void NegotiateFeeder(ScanSettings scanSettings)
        {
            try
            {
                if (scanSettings.UseDocumentFeeder.HasValue)
                {
                    Capability.SetCapability(Capabilities.FeederEnabled, scanSettings.UseDocumentFeeder.Value, _applicationId, SourceId);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }

            try
            {
                if (scanSettings.UseAutoFeeder.HasValue)
                {
                    Capability.SetCapability(Capabilities.AutoFeed, scanSettings.UseAutoFeeder == true && scanSettings.UseDocumentFeeder == true, _applicationId, SourceId);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }

            try
            {
                if (scanSettings.UseAutoScanCache.HasValue)
                {
                    Capability.SetCapability(Capabilities.AutoScan, scanSettings.UseAutoScanCache.Value, _applicationId, SourceId);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }
        }
Exemplo n.º 14
0
        public void StartScan(ScanSettings settings)
        {
            bool scanning = false;

            try
            {
                _messageHook.UseFilter = true;
                scanning = DataSource.Open(settings);
            }
            catch (TwainException)
            {
                DataSource.Close();
                EndingScan();
                throw;
            }
            finally
            {
                // Remove the message hook if scan setup failed
                if (!scanning)
                {
                    EndingScan();
                }
            }
        }
Exemplo n.º 15
0
        public bool Enable(ScanSettings settings)
        {
            var ui = new UserInterface
            {
                ShowUI     = (short)(settings.ShowTwainUi ? 1 : 0),
                ModalUI    = 1,
                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.º 16
0
        public void NegotiateColour(ScanSettings scanSettings)
        {
            try
            {
                Capability.SetBasicCapability(Capabilities.IPixelType, (ushort)GetPixelType(scanSettings), TwainType.UInt16, _applicationId, SourceId);
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }

            // TODO: Also set this for colour scanning
            try
            {
                if (scanSettings.Resolution.ColourSetting != ColourSetting.Colour)
                {
                    Capability.SetCapability(Capabilities.BitDepth, GetBitDepth(scanSettings), _applicationId, SourceId);
                }
            }
            catch
            {
                // Do nothing if the data source does not support the requested capability
            }
        }
Exemplo n.º 17
0
 /// <summary>
 /// Starts scanning.
 /// </summary>
 public void StartScanning(ScanSettings settings)
 {
     _dataSourceManager.StartScan(settings);
 }