Пример #1
0
        private void DisplayResolutions()
        {
            cbxResolution.Items.Clear();

            try
            {
                Twain32.Enumeration resolutions = _twain.Capabilities.XResolution.Get();

                if (resolutions.Count > 0)
                {
                    for (int index = 0; index < resolutions.Count; index++)
                    {
                        if (float.Parse(resolutions[index].ToString()) >= 200)
                        {
                            cbxResolution.Items.Add(resolutions[index].ToString());
                        }
                    }
                }
            }
            catch (TwainException ex)
            {
                LogFactory.CreateLog().LogError(ex);
                MessageBox.Show(ErrorMessages.ResolutionsNotAviableError, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        internal static Twain32.Enumeration ToEnumeration <T>(this object value)
        {
            Twain32.Enumeration _val = value.ToEnumeration();
            var _result = new object[_val.Count];

            for (int i = 0; i < _val.Count; i++)
            {
                _result[i] = typeof(T).IsEnum ? (T)_val[i] : Convert.ChangeType(_val[i], typeof(T));
            }
            return(Twain32.Enumeration.CreateEnumeration(_result, _val.CurrentIndex, _val.DefaultIndex));
        }
Пример #3
0
        public List <float> GetResolutions(int deviceIndex)
        {
            SetDevice(deviceIndex);
            Twain32.Enumeration _resolutions = _twain32.GetResolutions();
            List <float>        resolutions  = new List <float>();

            for (int i = 0; i < _resolutions.Count; i++)
            {
                resolutions.Add((float)_resolutions[i]);
            }
            _twain32.CloseDataSource();

            return(resolutions);
        }
Пример #4
0
        public List <string> GetPixelType()
        {
            _twain32.OpenDataSource();
            Twain32.Enumeration _pixelTypes = _twain32.GetPixelTypes();
            List <string>       pixelTypes  = new List <string>();

            for (int i = 0; i < _pixelTypes.Count; i++)
            {
                pixelTypes.Add(_pixelTypes[i].ToString());
            }
            _twain32.CloseDataSource();

            return(pixelTypes);
        }
Пример #5
0
        private void RunTwain()
        {
            logger.Debug("Run Twain");

            logger.Debug("IsTwain2Supported = {0}", _twain32.IsTwain2Supported);
            logger.Debug("IsTwain2Enable = {0}", _twain32.IsTwain2Enable);
            if (_twain32.OpenDataSource() == false)
            {
                string text = "Не удалось открыть источник.";
                logger.Error(text);
                throw new InvalidOperationException(text);
            }
            logger.Debug("DataSource is opened.");

                        #if DEBUG
            logger.Debug("XferMech.IsSupported=", _twain32.Capabilities.XferMech.IsSupported());
            logger.Debug("XferMech Support:");
            Twain32.Enumeration xferMech = _twain32.Capabilities.XferMech.Get();
            for (int i = 0; i < xferMech.Count; i++)
            {
                logger.Debug("[{0}] {1}", i, xferMech[i].ToString());
            }

            logger.Debug("All Capabilities");

            foreach (TwCap cap in Enum.GetValues(typeof(TwCap)))
            {
                if ((_twain32.IsCapSupported(cap) & TwQC.GetCurrent) != 0)
                {
                    logger.Debug("{0}(Current) = {1}", cap, _twain32.GetCurrentCap(cap));
                }
                else if ((_twain32.IsCapSupported(cap) & TwQC.Get) != 0)
                {
                    logger.Debug("{0} = {1}", cap, _twain32.GetCap(cap));
                }
                else
                {
                    logger.Debug("{0} = skiped", cap);
                }
            }
                        #endif

            _twain32.Capabilities.XferMech.Set(TwSX.Memory);
            //Feeder
            if (this._twain32.Capabilities.FeederEnabled.IsSupported(TwQC.Set))
            {
                this._twain32.Capabilities.FeederEnabled.Set(true);
                logger.Debug("TwCap.FeederEnabled = Enabled");

                if (this._twain32.Capabilities.AutoFeed.IsSupported(TwQC.Set))
                {
                    this._twain32.Capabilities.AutoFeed.Set(true);
                    logger.Debug("TwCap.AutoFeed = Enabled");
                }

                if (this._twain32.Capabilities.XferCount.IsSupported(TwQC.Set))
                {
                    this._twain32.Capabilities.XferCount.Set(-1);
                    logger.Debug("TwCap.XferCount = Enabled");
                }
            }

                        #if DEBUG
            //Отслеживаем все события
            _twain32.AcquireCompleted += delegate {
                logger.Debug("AcquireCompleted fired");
            };

            _twain32.AcquireError += (sender, e) => logger.Debug("AcquireError fired");

            _twain32.DeviceEvent += delegate {
                logger.Debug("DeviceEvent fired");
            };

            _twain32.EndXfer += delegate {
                logger.Debug("EndXfer fired");
            };

            _twain32.FileXferEvent += delegate {
                logger.Debug("FileXferEvent fired");
            };

            _twain32.MemXferEvent += delegate {
                logger.Debug("MemXferEvent fired");
            };

            _twain32.SetupFileXferEvent += delegate {
                logger.Debug("SetupFileXferEvent fired");
            };

            _twain32.SetupMemXferEvent += delegate {
                logger.Debug("SetupMemXferEvent fired");
            };

            _twain32.TwainStateChanged += (object sender, Twain32.TwainStateEventArgs e) => {
                logger.Debug("TwainStateChanged fired");
                logger.Debug("TwainState = {0}", e.TwainState);
            };

            _twain32.XferDone += delegate {
                logger.Debug("XferDone fired");
            };
                        #endif

            logger.Debug("Run Acquire");
            _twain32.Acquire();
            logger.Debug("After Acquire");
        }