Exemplo n.º 1
0
        private void btnSetCapability_Click(object sender, EventArgs e)
        {
            List <string> tempList = new List <string>();

            for (int i = 0; i <= m_TwainManager.SourceCount - 1; i++)
            {
                tempList.Add(m_TwainManager.SourceNameItems(Convert.ToInt16(i)));
            }
            SourceListWrapper tempSourceListWrapper = new SourceListWrapper(tempList);
            int iSelectIndex = tempSourceListWrapper.SelectSource();

            if (iSelectIndex == -1)
            {
                return;
            }
            else
            {
                m_TwainManager.SelectSourceByIndex(iSelectIndex);
                m_TwainManager.OpenSource();

                m_TwainManager.Capability = (Dynamsoft.TWAIN.Enums.TWCapability) 0x8001;
                m_TwainManager.CapType    = Dynamsoft.TWAIN.Enums.TWCapType.TWON_ONEVALUE;
                m_TwainManager.CapValue   = 1;
                bool   bRet     = m_TwainManager.CapSet();
                double dblValue = m_TwainManager.CapValue;
                if (bRet)
                {
                    MessageBox.Show("Successful.");
                }
                else
                {
                    MessageBox.Show("Failed.");
                }
            }
        }
Exemplo n.º 2
0
 private void cbxSources_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (((ComboBox)sender).SelectedIndex >= 0 && ((ComboBox)sender).SelectedIndex < m_TwainManager.SourceCount)
     {
         m_TwainManager.SelectSourceByIndex(cbxSources.SelectedIndex);
         m_TwainManager.OpenSource();
         m_TwainManager.ResetImageLayout();
         Margin tempMargin = m_TwainManager.GetImageLayout();
         fDefaultFrameLeft   = tempMargin.Left;
         fDefaultFrameTop    = tempMargin.Top;
         fDefaultFrameRight  = tempMargin.Right;
         fDefaultFrameBottom = tempMargin.Bottom;
         fDefaultFrameLeft   = (float)((int)(fDefaultFrameLeft * 10)) / 10;
         fDefaultFrameTop    = (float)((int)(fDefaultFrameTop * 10)) / 10;
         fDefaultFrameRight  = (float)((int)(fDefaultFrameRight * 10)) / 10;
         fDefaultFrameBottom = (float)((int)(fDefaultFrameBottom * 10)) / 10;
         edtFrameLeft.Text   = fDefaultFrameLeft.ToString();
         edtFrameTop.Text    = fDefaultFrameTop.ToString();
         edtFrameRight.Text  = fDefaultFrameRight.ToString();
         edtFrameBottom.Text = fDefaultFrameBottom.ToString();
         lblFrameLeft.Text   = string.Format("(0 ~ " + fDefaultFrameRight.ToString() + ")");
         lblFrameTop.Text    = string.Format("(0 ~ " + fDefaultFrameBottom.ToString() + ")");
         lblFrameRight.Text  = string.Format("(0 ~ " + fDefaultFrameRight.ToString() + ")");
         lblFrameBottom.Text = string.Format("(0 ~ " + fDefaultFrameBottom.ToString() + ")");
     }
 }
Exemplo n.º 3
0
        private void btnScan_Click(object sender, EventArgs e)
        {
            //m_TwainManager.SelectSource();
            //m_TwainManager.OpenSource();
            //m_TwainManager.IfAutoFeed = true;
            //m_TwainManager.IfFeederEnabled = true;
            //m_TwainManager.IfShowUI = false;
            //m_TwainManager.AcquireImage(this as IAcquireCallback);
            //dsViewer1.Visible = true;
            List <string> tempList = new List <string>();

            for (int i = 0; i < m_TwainManager.SourceCount; i++)
            {
                tempList.Add(m_TwainManager.SourceNameItems((short)i));
            }
            SourceListWrapper tempSourceListWrapper = new SourceListWrapper(tempList);

            int iSelectIndex = tempSourceListWrapper.SelectSource();

            if (iSelectIndex == -1)
            {
                return;
            }
            m_TwainManager.SelectSourceByIndex((short)iSelectIndex);
            m_TwainManager.OpenSource();
            m_TwainManager.IfAutoFeed      = true;
            m_TwainManager.IfFeederEnabled = true;
            m_TwainManager.IfShowUI        = false;
            m_TwainManager.AcquireImage(this as IAcquireCallback);
            dsViewer1.Visible = true;
        }
Exemplo n.º 4
0
        private void lbScan_MouseDown(object sender, MouseButtonEventArgs e)
        {
            string key = "active/" + "scan_now";

            if (!Window1.icons.ContainsKey(key))
            {
                try
                {
                    Window1.icons.Add(key, new ImageBrush(new BitmapImage(new Uri(Window1.imageDirectory + key + ".png", UriKind.RelativeOrAbsolute))));
                }
                catch { }
            }
            try
            {
                lbScan.Background = Window1.icons[key];
            }
            catch { }

            if (twain != null)
            {
                if (!IsFrameworkSatisfied())
                {
                    MessageBox.Show("WPF requires .NET Framework 3.5 SP1 or above. Please upgrade your .NET Framework.", "WpfControlsDemo", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
                twain.SelectSourceByIndex(cbxSources.SelectedIndex);
                twain.OpenSource();
                twain.IfDisableSourceAfterAcquire = true;
                twain.IfShowUI        = ckbShowUI.IsChecked.Value;
                twain.IfFeederEnabled = ckbADF.IsChecked.Value;
                twain.IfDuplexEnabled = ckbDuplex.IsChecked.Value;
                if (rbBW.IsChecked.Value)
                {
                    twain.PixelType = Dynamsoft.TWAIN.Enums.TWICapPixelType.TWPT_BW;
                    twain.BitDepth  = 1;
                }
                else if (rbGrey.IsChecked.Value)
                {
                    twain.PixelType = Dynamsoft.TWAIN.Enums.TWICapPixelType.TWPT_GRAY;
                    twain.BitDepth  = 8;
                }
                else if (rbColorful.IsChecked.Value)
                {
                    twain.PixelType = Dynamsoft.TWAIN.Enums.TWICapPixelType.TWPT_RGB;
                    twain.BitDepth  = 24;
                }
                twain.AcquireImage(this as IAcquireCallback);
            }
        }
Exemplo n.º 5
0
        private void AcquireImage()
        {
            try
            {
                m_TwainManager.SelectSourceByIndex(Convert.ToInt16(cmbSource.SelectedIndex));
                m_TwainManager.IfShowUI = chkboxIfShowUI.Checked;
                m_TwainManager.OpenSource();
                m_TwainManager.IfDisableSourceAfterAcquire = true;

                m_TwainManager.IfShowUI = chkboxIfShowUI.Checked;
                m_TwainManager.AcquireImage(this as IAcquireCallback);
            }
            catch (Exception exp)
            {
                this.txtboxErrMessage.AppendText(exp.Message);
                this.txtboxErrMessage.AppendText("\r\n");
            }
        }
Exemplo n.º 6
0
        private void btnAcquire_Click(object sender, System.EventArgs e)
        {
            if (dlgFileSave.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }

            strFileName = dlgFileSave.FileName;

            m_TwainManager.OpenSource();

            try
            {
                m_TwainManager.TransferMode = Dynamsoft.TWAIN.Enums.TWICapSetupXFer.TWSX_FILE;
            }
            catch (Exception exp)
            {
                MessageBox.Show("The license for TWAIN module is invalid.Please contact [email protected] to get a trial license.");
                return;
            }


            //Since the TWSX_FILE mode is not required by TWAIN specification,
            //it is better to read the value back to see if the File transfer mode is supported by the Source
            if (m_TwainManager.TransferMode == Dynamsoft.TWAIN.Enums.TWICapSetupXFer.TWSX_FILE)
            {                                                                                                 //the source supports the TWSX_FILE transfer mode.
                m_TwainManager.SetFileXFERInfo(strFileName, Dynamsoft.TWAIN.Enums.TWICapFileFormat.TWFF_BMP); //Sets file name and file format information.
                m_TwainManager.IfShowUI = false;
                m_TwainManager.IfDisableSourceAfterAcquire = true;
                m_TwainManager.EnableSource(this as IAcquireCallback); //Acquire the image.
            }
            else                                                       //the source doesn't support the TWSX_FILE transfer mode.
            {
                MessageBox.Show("The source doesn't support the DiskFile transfer mode.");
            }
        }