Exemple #1
0
        /// <summary>
        /// Handle an image.  a_bitmap is passed by reference so that this function can
        /// dispose and null it out to gain access to the file that's backing it.  The
        /// calling toolkit function will never perform any action with a_bitmap after
        /// this function returns.
        /// </summary>
        /// <param name="a_szDg">Data group that preceeded this call</param>
        /// <param name="a_szDat">Data argument type that preceeded this call</param>
        /// <param name="a_szMsg">Message that preceeded this call</param>
        /// <param name="a_sts">Current status</param>
        /// <param name="a_bitmap">C# bitmap of the image</param>
        /// <param name="a_szFile">File name, if doing a file transfer</param>
        /// <param name="a_szTwimageinfo">data collected for us</param>
        /// <param name="a_abImage">a byte array of the image</param>
        /// <param name="a_iImageOffset">byte offset where the image data begins</param>
        private TWAINCSToolkit.MSG ReportImage
        (
            string a_szTag,
            string a_szDg,
            string a_szDat,
            string a_szMsg,
            TWAIN.STS a_sts,
            Bitmap a_bitmap,
            string a_szFile,
            string a_szTwimageinfo,
            byte[] a_abImage,
            int a_iImageOffset
        )
        {
            // We're leaving...
            if (m_graphics1 == null)
            {
                return(TWAINCSToolkit.MSG.RESET);
            }

            // Let us be called from any thread...
            if (this.InvokeRequired)
            {
                // We need a copy of the bitmap, because we're not going to wait
                // for the thread to return.  Be careful when using EndInvoke.
                // It's possible to create a deadlock situation with the Stop
                // button press.
                BeginInvoke(new MethodInvoker(delegate() { ReportImage(a_szTag, a_szDg, a_szDat, a_szMsg, a_sts, a_bitmap, a_szFile, a_szTwimageinfo, a_abImage, a_iImageOffset); }));
                return(TWAINCSToolkit.MSG.ENDXFER);
            }

            // We're processing end of scan...
            if (a_bitmap == null)
            {
                // Report errors, but only if the driver's indicators have
                // been turned off, otherwise we'll hit the user with multiple
                // dialogs for the same error...
                if (!m_blIndicators && (a_sts != TWAIN.STS.SUCCESS))
                {
                    MessageBox.Show("End of session status: " + a_sts);
                }

                // Get ready for the next scan...
                SetButtons(EBUTTONSTATE.OPEN);
                return(TWAINCSToolkit.MSG.ENDXFER);
            }

            // Display the image...
            if (m_iUseBitmap == 0)
            {
                m_iUseBitmap = 1;
                LoadImage(ref m_pictureboxImage1, ref m_graphics1, ref m_bitmapGraphic1, a_bitmap);
            }


            // All done...
            return(TWAINCSToolkit.MSG.ENDXFER);
        }
        /// <summary>
        /// 获取当前传输模式
        /// </summary>
        /// <returns></returns>
        private string GetTwainTransferMode()
        {
            string szTwmemref = "ICAP_XFERMECH";
            string szStatus   = "";

            TWAIN.STS sts = m_twaincstoolkit.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_GETCURRENT", ref szTwmemref, ref szStatus);

            string[] pros = (szTwmemref + ",,,,").Split(',');

            return(pros[3]);
        }
Exemple #3
0
        /// <summary>
        /// Handle an image.  a_bitmap is passed by reference so that this function can
        /// dispose and null it out to gain access to the file that's backing it.  The
        /// calling toolkit function will never perform any action with a_bitmap after
        /// this function returns.
        /// </summary>
        /// <param name="a_szDg">Data group that preceeded this call</param>
        /// <param name="a_szDat">Data argument type that preceeded this call</param>
        /// <param name="a_szMsg">Message that preceeded this call</param>
        /// <param name="a_sts">Current status</param>
        /// <param name="a_bitmap">C# bitmap of the image</param>
        /// <param name="a_szFile">File name, if doing a file transfer</param>
        /// <param name="a_szTwimageinfo">data collected for us</param>
        /// <param name="a_abImage">a byte array of the image</param>
        /// <param name="a_iImageOffset">byte offset where the image data begins</param>
        public TWAINCSToolkit.MSG ReportImage
        (
            string a_szTag,
            string a_szDg,
            string a_szDat,
            string a_szMsg,
            TWAIN.STS a_sts,
            Bitmap a_bitmap,
            string a_szFile,
            string a_szTwimageinfo,
            byte[] a_abImage,
            int a_iImageOffset
        )
        {
            // We're leaving...
            if (m_blClosing || (m_graphics1 == null) || (a_bitmap == null))
            {
                return(TWAINCSToolkit.MSG.RESET);
            }

            // Let us be called from any thread...
            if (this.InvokeRequired)
            {
                // We need a copy of the bitmap, because we're not going to wait
                // for the thread to return.  Be careful when using EndInvoke.
                // It's possible to create a deadlock situation with the Stop
                // button press.
                BeginInvoke(new MethodInvoker(delegate() { ReportImage(a_szTag, a_szDg, a_szDat, a_szMsg, a_sts, a_bitmap, a_szFile, a_szTwimageinfo, a_abImage, a_iImageOffset); }));
                return(TWAINCSToolkit.MSG.ENDXFER);
            }

            // Display the image...
            switch (m_iCurrentPictureBox)
            {
            default:
            case 0:
                LoadImage(ref m_pictureboxImage1, ref m_graphics1, ref m_bitmapGraphic1, a_bitmap);
                break;

            case 1:
                LoadImage(ref m_pictureboxImage2, ref m_graphics2, ref m_bitmapGraphic2, a_bitmap);
                break;

            case 2:
                LoadImage(ref m_pictureboxImage3, ref m_graphics3, ref m_bitmapGraphic3, a_bitmap);
                break;

            case 3:
                LoadImage(ref m_pictureboxImage4, ref m_graphics4, ref m_bitmapGraphic4, a_bitmap);
                break;

            case 4:
                LoadImage(ref m_pictureboxImage5, ref m_graphics5, ref m_bitmapGraphic5, a_bitmap);
                break;

            case 5:
                LoadImage(ref m_pictureboxImage6, ref m_graphics6, ref m_bitmapGraphic6, a_bitmap);
                break;

            case 6:
                LoadImage(ref m_pictureboxImage7, ref m_graphics7, ref m_bitmapGraphic7, a_bitmap);
                break;

            case 7:
                LoadImage(ref m_pictureboxImage8, ref m_graphics8, ref m_bitmapGraphic8, a_bitmap);
                break;
            }

            // Next picture box...
            if (++m_iCurrentPictureBox >= 8)
            {
                m_iCurrentPictureBox = 0;
            }

            // All done...
            return(TWAINCSToolkit.MSG.ENDXFER);
        }
Exemple #4
0
        /// <summary>
        /// 初始化设备
        /// </summary>
        /// <param name="devName"></param>
        public bool InitDevice(string devName)
        {
            _scanDevName = devName;

            string szStatus = "";

            if (_scanCore == null)
            {
                InitCore();
            }

            _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_SET", ref _scanDevName, ref szStatus);

            // Open it...

            TWAIN.STS sts = _scanCore.Send("DG_CONTROL", "DAT_IDENTITY", "MSG_OPENDS", ref _scanDevName, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                //MessageBox.Show("Unable to open scanner (it is turned on and plugged in?)");

                return(false);
            }

            // Strip off unsafe chars.  Sadly, mono let's us down here...
            m_szProductDirectory = TWAINCSToolkit.CsvParse(_scanDevName)[11];
            foreach (char c in new char[41]
            {
                '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07',
                '\x08', '\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12',
                '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
                '\x1E', '\x1F', '\x22', '\x3C', '\x3E', '\x7C', ':', '*', '?', '\\', '/'
            }
                     )
            {
                m_szProductDirectory = m_szProductDirectory.Replace(c, '_');
            }


            szStatus = "";
            string szCapability = "ICAP_XFERMECH,TWON_ONEVALUE,TWTY_UINT16,2";

            sts = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                return(false);
            }

            // Decide whether or not to show the driver's window messages...
            szStatus     = "";
            szCapability = "CAP_INDICATORS,TWON_ONEVALUE,TWTY_BOOL," + (m_blIndicators ? "1" : "0");
            sts          = _scanCore.Send("DG_CONTROL", "DAT_CAPABILITY", "MSG_SET", ref szCapability, ref szStatus);
            if (sts != TWAIN.STS.SUCCESS)
            {
                return(false);
            }

            if (m_formsetup == null)
            {
                m_formsetup = new FormSetup(ref _scanCore, m_szProductDirectory);
            }


            return(true);
        }