Exemple #1
0
        private void _rdTransferFile_CheckedChanged(object sender, System.EventArgs e)
        {
            int    format;
            string fileName;

            _transferMode           = TwainTransferMode.File;
            _cmbFileFormats.Enabled = true;
            _btnBrowse.Enabled      = true;

            fileName       = this._txtFileName.Text;
            _btnOK.Enabled = (fileName != "");

            // disable other options
            _cbUseBufferSize.Enabled = false;
            _txtBufferSize.Enabled   = false;
            _btnLEADFormats.Enabled  = false;

            try
            {
                TwainCapability twnCap = _session.GetCapability(TwainCapabilityType.ImageImageFileFormat, TwainGetCapabilityMode.GetValues);

                switch (twnCap.Information.ContainerType)
                {
                case TwainContainerType.Enumeration:
                {
                    _cmbFileFormats.Items.Clear();
                    int count = twnCap.EnumerationCapability.Count;
                    _format = new RasterImageFormat[count];
                    for (int i = 0; i < count; i++)
                    {
                        if (twnCap.EnumerationCapability.ItemType == TwainItemType.Uint16)
                        {
                            format = Convert.ToUInt16(twnCap.EnumerationCapability.GetValue(i));
                            AddScannerFormats(format, i);
                        }
                    }
                    break;
                }

                case TwainContainerType.OneValue:
                {
                    _cmbFileFormats.Items.Clear();
                    if (twnCap.OneValueCapability.ItemType == TwainItemType.Uint16)
                    {
                        _format = new RasterImageFormat[1];
                        format  = Convert.ToUInt16(twnCap.OneValueCapability.Value);
                        AddScannerFormats(format, 0);
                    }
                    break;
                }
                }

                _cmbFileFormats.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                Messager.ShowError(this, ex);
            }
        }
        public bool GetCap()
        {
            bool flag = true;

            if (capId == TwCap.ICAP_XRESOLUTION || capId == TwCap.ICAP_YRESOLUTION)
            {
                flag = SetInch();
            }
            //if (capId == TwCap.ICAP_THRESHOLD)
            //{
            //    flag = SetBitDepthReduction();
            //}
            if (flag)
            {
                if (capId == TwCap.ECAP_PAPERSOURCE)
                {
                    GetPaperSource();
                }
                else
                {
                    TwCapability cap = new TwCapability(capId);

                    if (twSession.GetCapability(ref cap))
                    {
                        IntPtr intPtr = cap.contentValuePtr;
                        switch (cap.contentType)
                        {
                        case TwOn.One:
                            GetCapFromOneValue(intPtr);
                            break;

                        case TwOn.Array:
                            GetCapFromArray(intPtr);
                            break;

                        case TwOn.Enum:
                            GetCapFromEnumeration(intPtr);
                            break;

                        case TwOn.Range:
                            GetCapFromRange(intPtr);
                            break;

                        default:
                        {
                            logger.Debug("the contentType in TwCapability is wrong");
                            flag = false;
                        }
                        break;
                        }
                    }
                    if (cap.contentValuePtr != null)
                    {
                        TwainSession.GlobalFree(cap.contentValuePtr);
                    }
                }
            }
            return(flag);
        }