Exemple #1
0
        bool IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message m)
        {
            TwainCommand Tc = Tw.PassMessage(ref m);

            if (Tc == TwainCommand.Not)
            {
                return(false);
            }
            if (Tc == TwainCommand.Null)//by dh
            {
                return(false);
            }
            switch (Tc)
            {
            case TwainCommand.CloseRequest:
                timer1.Stop();
                break;

            case TwainCommand.CloseOk:
                EndScanning();
                Tw.CloseSrc();
                break;

            case TwainCommand.DeviceEvent:
                timer1.Stop();
                break;

            case TwainCommand.TransferReady:
                timer1.Enabled  = true;
                timer1.Interval = 10;
                timer1.Start();
                ArrayList LstPic = Tw.TransferPictures();    //点击扫描按钮
                EndScanning();
                Tw.CloseSrc();
                string inhosTimes = txtTimes.Text;
                if (inhosTimes.ToString().Length == 1)
                {
                    inhosTimes = "0" + inhosTimes;
                }
                for (int i = 0; i < LstPic.Count; ++i)
                {
                    IntPtr Img = (IntPtr)LstPic[i];
                    Page++;
                    string page     = SetPage(Page);
                    string fileName = txtID.Text + "_" + inhosTimes + "_" + page + "_00";
                    bmpptr = GlobalLock(Img);
                    pixptr = GetPixelInfo(bmpptr);
                    Gdip.SaveDIBAs(txtFolder.Text, fileName, bmpptr, pixptr); //保存图片
                }
                isSuccessEnd = true;                                          //已完成
                OnRefresh(null, null);                                        //刷新图片采集主窗体
                timer1.Stop();
                this.Close();
                break;
            }
            return(true);
        }
Exemple #2
0
        bool IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message m)
        {
            TwainCommand Tc = Tw.PassMessage(ref m);

            if (Tc == TwainCommand.Not)
            {
                return(false);
            }
            if (Tc == TwainCommand.Null)//by dh
            {
                return(false);
            }
            switch (Tc)
            {
            case TwainCommand.CloseRequest:
            case TwainCommand.CloseOk:
                EndScanning();
                Tw.CloseSrc();
                break;

            case TwainCommand.DeviceEvent:
                break;

            case TwainCommand.TransferReady:
                ArrayList LstPic = Tw.TransferPictures();
                EndScanning();
                Tw.CloseSrc();
                string inhosTimes = txtTimes.Text;
                if (inhosTimes.ToString().Length == 1)
                {
                    inhosTimes = "0" + inhosTimes;
                }
                for (int i = 0; i < LstPic.Count; ++i)
                {
                    IntPtr Img = (IntPtr)LstPic[i];
                    Page++;
                    string page     = SetPage(Page);
                    string fileName = LURecordNO.DisplayText + "_" + inhosTimes + "_" + page + "_00";
                    bmpptr = GlobalLock(Img);
                    pixptr = GetPixelInfo(bmpptr);
                    Gdip.SaveDIBAs(txtFolder.Text, fileName, bmpptr, pixptr);    //保存图片
                }
                DataTable data = CreatePictureDate(txtFolder.Text);
                pictureGrid.DataSource = data;
                if (data != null && data.Rows.Count > 0)
                {
                    pictureView.FocusedRowHandle = data.Rows.Count - 1;
                }
                txtPage.Text = SetPage(Page + 1);
                break;
                //case TwainCommand.Null://by dh
                //    EndScanning();
                //    Tw.CloseSrc();
                //    break;
            }
            return(true);
        }
Exemple #3
0
        bool IMessageFilter.PreFilterMessage(ref System.Windows.Forms.Message m)
        {
            TwainCommand Tc = Tw.PassMessage(ref m);

            if (Tc == TwainCommand.Not)
            {
                return(false);
            }
            //if (Tc == TwainCommand.Null)//by dh
            //{
            //    return false;
            //}
            switch (Tc)
            {
            case TwainCommand.CloseRequest:
            case TwainCommand.CloseOk:
                EndScanning();
                Tw.CloseSrc();
                break;

            case TwainCommand.DeviceEvent:
                break;

            case TwainCommand.TransferReady:
                ArrayList LstPic = Tw.TransferPictures();
                EndScanning();
                Tw.CloseSrc();
                string inhosTimes = txtTimes.Text;
                if (inhosTimes.ToString().Length == 1)
                {
                    inhosTimes = "0" + inhosTimes;
                }
                for (int i = 0; i < LstPic.Count; ++i)
                {
                    IntPtr Img = (IntPtr)LstPic[i];
                    Page++;
                    string page     = SetPage(Page);
                    string fileName = LURecordNO.DisplayText + "_" + inhosTimes + "_" + page + "_00";
                    bmpptr = GlobalLock(Img);
                    pixptr = GetPixelInfo(bmpptr);
                    Gdip.SaveDIBAs(txtFolder.Text, fileName, bmpptr, pixptr); //保存图片
                }
                for (int i = 0; i < LstPic.Count; ++i)                        //回收内存
                {
                    IntPtr Img = (IntPtr)LstPic[i];
                    Marshal.FreeHGlobal(Img);
                }
                DataTable data = CreatePictureDate(txtFolder.Text);
                pictureGrid.DataSource = data;
                if (data != null && data.Rows.Count > 0)
                {
                    pictureView.FocusedRowHandle = data.Rows.Count - 1;
                }
                txtStartPage.Text = SetPage(Page + 1);
                LstPic.Clear();
                //GC.SuppressFinalize(this);
                GC.Collect();    //回收内存
                //dibhand = IntPtr.Zero;
                //bmpptr = IntPtr.Zero;
                //pixptr = IntPtr.Zero;
                //Marshal.FreeCoTaskMem(dibhand);
                //Marshal.FreeCoTaskMem(bmpptr);
                //Marshal.FreeCoTaskMem(pixptr);
                //Marshal.FreeHGlobal(dibhand);
                //Marshal.FreeHGlobal(bmpptr);
                //Marshal.FreeHGlobal(pixptr);
                break;
            }
            return(true);
        }