Пример #1
0
 private void _LoadImage(string path)
 {
     if (path == null || path.Length == 0)
     {
         return;
     }
     if (!File.Exists(path))
     {
         return;
     }
     if (ImagePath != path)
     {
         RenderState  = false;
         this.Image   = Image.FromFile(path);
         this.Frames  = new FrameDimension(this.Image.FrameDimensionsList[0]);
         FrameCount   = Image.GetFrameCount(this.Frames);
         CurrentFrame = 0;
         ImagePath    = path;
         this.Width   = Image.Width;
         this.Height  = Image.Height;
         try
         {
             Gdip.InterpolationMode = InterpolationMode.HighQualityBicubic;
             Gdip.DrawImage(Image, new Rectangle(0, 0, this.Width, this.Height));
         }
         catch { }
     }
 }
Пример #2
0
 public GifPlayer()
 {
     InitializeComponent();
     Gdip    = this.CreateGraphics();
     Looping = new Thread(() =>
     {
         while (true)
         {
             if (Image != null && RenderState)
             {
                 var isPlaying = CurrentState == OsuStatus.Playing;
                 var delay     = (int)(Delay / (isPlaying ? ModifierDelayMultiply : 1));
                 // atleast 30bpm
                 if (delay > 2000)
                 {
                     delay = 2000;
                 }
                 Thread.Sleep(delay);
                 if (CurrentFrame >= FrameCount)
                 {
                     CurrentFrame = 0;
                 }
                 Image.SelectActiveFrame(this.Frames, CurrentFrame++);
                 Gdip.DrawImage(Image, new Rectangle(0, 0, this.Width, this.Height));
             }
             Thread.Sleep(1);
         }
     });
     Looping.Start();
 }
Пример #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:
                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);
        }
Пример #4
0
 public void Save()
 {
     Gdip.AutoSaveDIBAs(m_ScannerPath, this.Text, bmpptr, pixptr);
     menuItemSave.Visible = false;
     if (m_bAutoScanNext)
     {
         this.Close();
     }
 }
Пример #5
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);
        }
Пример #6
0
        private void SaveImages()
        {
            int ImgNumber = 0;

            ArrayList pics = tw.TransferPictures();

            EndingScan();
            tw.CloseSrc();
            picnumber++;

            oImage.CompanyID  = CompanyID;
            oImage.CustomerID = oCustomer.CustomerID;
            oImage.Teacher    = txtTeacher.Text;
            oImage.BatchID    = oTeacher.ID;
            oImage.Teacher    = oTeacher.Name;

            int i;

            for (i = 0; i < pics.Count; i++)
            {
                IntPtr img = (IntPtr)pics[i];
                {
                    bmprect = new Rectangle(0, 0, 0, 0);
                    bmpptr  = GlobalLock(img);
                    pixptr  = GetPixelInfo(bmpptr);
                    int picnum = ImgNumber + i + 1;

                    //Saving in Images Table

                    oImage.Date = DateTime.Now;
                    oImage.Insert();

                    Gdip.SavePicToFile(oImage.FilePath, bmpptr, pixptr);
                }
            }
            if (pics.Count > 0)
            {
                oCustomer.Teachers[oCustomer.Teachers.Index].Scanned = true;

                oTeacher.Scanned = true;
                oTeacher.UpdateStatus();
                if (this.SetNextTeacher())
                {
                    txtTeacher.Text = oTeacher.Name;
                }
                else
                {
                    txtTeacher.Clear();
                    txtTeacher.Focus();
                }
            }
        }
Пример #7
0
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            //Gdip.SaveDIBAs(this.Text, bmpptr, pixptr);
            string str = Gdip.SaveDIBtoTemp(bmpptr, pixptr);

            //pBox.Image = Image.FromFile(str);
            pBox.ImageLocation = str;

            //Rectangle cltrect = ClientRectangle;
            //Rectangle clprect = e.ClipRectangle;
            //Point scrol = AutoScrollPosition;

            //Rectangle realrect = clprect;
            //realrect.X -= scrol.X;
            //realrect.Y -= scrol.Y;

            //SolidBrush brbg = new SolidBrush(Color.Black);
            //if (realrect.Right > bmprect.Width)
            //{
            //  Rectangle bgri = clprect;
            //  int ovri = bmprect.Width - realrect.X;
            //  if (ovri > 0)
            //  {
            //    bgri.X += ovri;
            //    bgri.Width -= ovri;
            //  }
            //  e.Graphics.FillRectangle(brbg, bgri);
            //}

            //if (realrect.Bottom > bmprect.Height)
            //{
            //  Rectangle bgbo = clprect;
            //  int ovbo = bmprect.Height - realrect.Y;
            //  if (ovbo > 0)
            //  {
            //    bgbo.Y += ovbo;
            //    bgbo.Height -= ovbo;
            //  }
            //  e.Graphics.FillRectangle(brbg, bgbo);
            //}

            //realrect.Intersect(bmprect);
            //if (!realrect.IsEmpty)
            //{
            //  int bot = bmprect.Height - realrect.Bottom;
            //  IntPtr hdc = e.Graphics.GetHdc();
            //  SetDIBitsToDevice(hdc, clprect.X, clprect.Y, realrect.Width, realrect.Height,
            //      realrect.X, bot, 0, bmprect.Height, pixptr, bmpptr, 0);
            //  e.Graphics.ReleaseHdc(hdc);
            //}
        }
Пример #8
0
        public string SaveAs_()
        {
            string tempPath = Path.GetTempPath() + Path.GetRandomFileName() + ".jpg";

            try
            {
                Gdip.SaveDIBAs(tempPath, bmpptr, pixptr);
            }
            catch (System.Exception ex)
            {
                return("");
            }
            //Gdip.SaveDIBAs(this.Text, bmpptr, pixptr);
            return(tempPath);
        }
Пример #9
0
 private void menuItemSaveAs_Click(object sender, System.EventArgs e)
 {
     Gdip.SaveDIBAs(this.Text, bmpptr, pixptr);
 }
Пример #10
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);
        }
Пример #11
0
        /// <summary>
        /// 初始化扫描进程显示界面
        /// 添加文件保存后台线程的三个回调方法
        /// </summary>
        private void Init()
        {
            worker.DoWork += delegate(object s, DoWorkEventArgs args)
            {
                String fileSingleName;      // 每次传输返回的文件名

                //获取传输模式
                TwMode mode = twSession.GetCurrentTransferMode();
                switch (mode)
                {
                case TwMode.TWSX_FILE:
                    transferFileAction = twSession.TransferSingleFileInFileMode;
                    break;

                case TwMode.TWSX_NATIVE:
                    transferFileAction = twSession.TransferSingleFileInNativeMode;
                    break;

                default:
                    break;
                }

                // 1:初始化GDI+
                Gdip.InitGDIPlus();

                //2:依次传输每个文件
                logger.Debug("开始传输文件:" + DateTime.Now);
                if (transferFileAction != null)
                {
                    int count = 0;
                    try
                    {
                        do
                        {
                            logger.Debug("开始传输单个文件: count = " + count);
                            //传输单个文件
                            transferResult = transferFileAction(fileType, out fileSingleName, resolution, out msg);
                            logger.Debug("传输单个文件结束: result = " + transferResult);
                            logger.Debug("开始结束一次传输过程。");
                            twSession.EndXfer(out count);
                            logger.Debug("结束一次传输过程结束: count = " + count);
                            //2.1:传输成功则检查文件大小
                            if (transferResult == TwRC.XferDone)
                            {
                                logger.Debug("得到一个传输文件: " + DateTime.Now);
                                if (fileSingleName != null)
                                {
                                    //A:判断读取的文件大小,零字节则不添加到列表中
                                    FileInfo fileInfo = new FileInfo(fileSingleName);
                                    if (fileInfo.Length > blankSizeLimit && fileInfo.Length < maxImageSize)
                                    {
                                        cnt++;
                                        fileNames.Add(fileSingleName);
                                        worker.ReportProgress(fileNames.Count);
                                        logger.Debug("添加文件到列表,文件名: " + fileSingleName);
                                        //iacTwain.RaiseGetOnePageEvent(fileSingleName);
                                    }
                                    //B:否则删除文件
                                    else
                                    {
                                        fileInfo.Delete();
                                        logger.Info("删除太大或太小的扫描结果文件。");
                                    }
                                }
                                else
                                {
                                    logger.Debug("文件名为null。");
                                }
                            }
                            //2.2:传输失败则跳出循环
                            else
                            {
                                logger.Debug("传输失败,跳出循环。");
                                //if (count != 0) //如果扫描仪还有图像未传输,通知扫描仪清空
                                //    twSession.ResetScanner();
                                break;
                            }
                            logger.Debug("结束传输单个文件: count = " + count);
                        } while (count != 0 && count != -2);
                        logger.Debug("结束循环 :" + DateTime.Now);
                    }
                    #region 异常处理
                    catch (ArgumentNullException e)
                    {
                        logger.Error("参数为空异常,异常信息: " + e.Message);
                    }
                    catch (ArgumentException e)
                    {
                        logger.Error("无效参数异常,异常信息: " + e.Message);
                    }
                    catch (System.Security.SecurityException e)
                    {
                        logger.Error("安全性错误引发的异常,异常信息: " + e.Message);
                    }
                    catch (UnauthorizedAccessException e)
                    {
                        logger.Error("IO错误或指定类型引发的安全性错误引发的异常,异常信息: " + e.Message);
                    }
                    catch (PathTooLongException e)
                    {
                        logger.Error("路径太长引发的异常,异常信息: " + e.Message);
                    }
                    catch (NotSupportedException e)
                    {
                        logger.Error("调用的方法不受支持或视图读取,查找或写入不支持调用功能的流引发的异常,异常信息: " + e.Message);
                    }
                    catch (IOException e)
                    {
                        logger.Error("IO异常,异常信息: " + e.Message);
                    }
                    catch (Exception e)
                    {
                        logger.Error("操作发生异常,异常信息: " + e.Message);
                    }
                    finally
                    {
                        Gdip.ClearGDIPlus();
                    }
                    #endregion
                }
            };

            worker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
            {
                buttonControl.Content = "已经扫描传输" + cnt + "页";
            };

            worker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
            {
                if (transferResult == TwRC.Failure)
                {
                    MessageBox.Show("扫描失败:" + msg);
                }
                else
                {
                    if (twSession.State >= TwState.OpenDS)
                    {
                        twSession.DisableDS();
                    }
                }

                if (transferResult == TwRC.TransferError)
                {
                    MessageBox.Show("传输失败:" + msg);
                }

                if (transferResult == TwRC.BadValue)
                {
                    MessageBox.Show("扫描仪当前设置不支持文件格式" + fileType + ",请重新设置");
                }

                Close();
            };
        }
Пример #12
0
 public void saveImg()
 {
     Gdip.SaveImg(this.Text + ".bmp", bmpptr, pixptr);
 }
Пример #13
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            string       sFileImage = "";
            TwainCommand cmd        = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Null)
            {
                //EndingScan();
                return(false);
            }
            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
                EndingScan();
                tw.CloseSrc();
                break;

            case TwainCommand.CloseOk:
                EndingScan();
                tw.CloseSrc();
                break;

            case TwainCommand.DeviceEvent:
                break;

            case TwainCommand.TransferReady:
                IntPtr    img;
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                for (int i = 0; i < pics.Count; i++)
                {
                    img = (IntPtr)pics[i];
                    PicForm newpic = new PicForm(img);
                    int     picnum = i + 1;
                }
                if (pics.Count > 0)
                {
                    sFileImage = getFileImage().Trim();

                    try
                    {
                        if (!Directory.Exists(ImagePath))
                        {
                            DirectoryInfo di = Directory.CreateDirectory(ImagePath);
                        }

                        string filepath = ImagePath + @"\" + sFileImage.Trim();

                        Gdip.SaveDIBAsFile(filepath, PicForm.bmpptr, PicForm.pixptr);

                        Image picForCheck = Image.FromFile(filepath);

                        if (picForCheck != null)
                        {
                            System.IO.FileInfo file = new System.IO.FileInfo(filepath);
                            CheckAndSaveImage(picForCheck, file);
                        }
                    }
                    catch { }
                }
                else
                {
                    MessageBox.Show("Ошибка сканирования!");
                }
                break;
            }

            return(true);
        }
Пример #14
0
 public void SaveTemp(String pFileName)
 {
     Gdip.SaveDIBAsTemp(pFileName, bmpptr, pixptr);
 }
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                int ImgNumber = 0;

                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                picnumber++;

                if (!this.mnShowImages.Checked)
                {
                    if (oImages.Find(_CompanyID, _CustomerID, _Teacher))
                    {
                        //  ImgNumber = oImages._ImageFinal;
                    }

                    // oImages._ImageInitial = 1;
                    oImages.CompanyID  = _CompanyID;
                    oImages.CustomerID = _CustomerID;
                }



                int i;
                for (i = 0; i < pics.Count; i++)
                {
                    IntPtr img = (IntPtr)pics[i];

                    if (this.mnShowImages.Checked)
                    {
                        PicForm newpic = new PicForm(img);
                        newpic.MdiParent = this;
                        //Panel.Controls.Add((Control)newpic);

                        int picnum = ImgNumber + i + 1;
                        //newpic.Text = "ScanPass" + picnumber.ToString() + "_Pic" + picnum.ToString();
                        newpic.Text = "Order" + picnumber.ToString() + "_Pic" + picnum.ToString();
                        newpic.Show();
                    }
                    else
                    {
                        bmprect = new Rectangle(0, 0, 0, 0);
                        bmpptr  = GlobalLock(img);
                        pixptr  = GetPixelInfo(bmpptr);
                        int picnum = ImgNumber + i + 1;

                        //Gdip.SavePicToFile("ScanPass" + picnum.ToString() + ".tiff", bmpptr, pixptr);
                        Gdip.SavePicToFile("Images/Order-" + _CompanyID.PadLeft(2, '0') + _CustomerID.PadLeft(4, '0') + _Batch.PadLeft(3, '0') + picnum.ToString().PadLeft(4, '0') + ".tif", bmpptr, pixptr);
                    }
                }
                if (!this.mnShowImages.Checked)
                {
                    //Save Batch Here

                    //   oImages._ImageFinal = ImgNumber + i;
                    //oImages._NumberImages += i;
                    oImages.Teacher = _Teacher;
                    oImages.Save();
                }

                break;
            }

            default:
            {
                return(false);
            }
            }

            return(true);
        }
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            TwainCommand cmd = tw.PassMessage(ref m);

            if (cmd == TwainCommand.Not)
            {
                return(false);
            }

            switch (cmd)
            {
            case TwainCommand.CloseRequest:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                int ImgNumber = 0;

                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                picnumber++;

                if (oBatch.Find(_CompanyID, _CustomerID, _Teacher))
                {
                    //ImgNumber = oBatch._ImageFinal;
                }

                //    oBatch._ImageInitial = 1;
                oBatch.CompanyID = _CompanyID;
                //    oBatch.CustomerID = _CustomerID;


                int i;
                for (i = 0; i < pics.Count; i++)
                {
                    IntPtr img = (IntPtr)pics[i];

                    {
                        bmprect = new Rectangle(0, 0, 0, 0);
                        bmpptr  = GlobalLock(img);
                        pixptr  = GetPixelInfo(bmpptr);
                        int picnum = ImgNumber + i + 1;

                        //Gdip.SavePicToFile("ScanPass" + picnum.ToString() + ".tiff", bmpptr, pixptr);
                        Gdip.SavePicToFile("Images/Order-" + _CompanyID.PadLeft(2, '0') + _CustomerID.PadLeft(4, '0') + _Batch.PadLeft(3, '0') + picnum.ToString().PadLeft(4, '0') + ".tif", bmpptr, pixptr);
                    }
                }

                //Save Batch Here

                //oBatch._ImageFinal = ImgNumber + i;
                //oBatch._NumberImages += i;
                //oBatch.Teacher = _Teacher;
                oBatch.Save();



                break;
            }

            default:
            {
                return(false);
            }
            }

            return(true);
        }
Пример #17
0
        /// <summary>
        /// 循环传输每张图像
        /// </summary>
        private void TransferFiles()
        {
            //1:查询相关数据
            string fileSingleName;      // 每次传输返回的文件名
            string msg = null;
            //获得文件格式
            CapInfo capInfo;

            capInfo = twSession.GetScannerCap(TwCap.ICAP_IMAGEFILEFORMAT);
            string       intStr     = capInfo.CurrentIntStr;
            string       enumStr    = twSession.ConvertIntStringToEnumString(TwCap.ICAP_IMAGEFILEFORMAT, intStr);
            TwFileFormat fileFormat = (TwFileFormat)Enum.Parse(typeof(TwFileFormat), enumStr);

            //获取分辨率
            capInfo = twSession.GetScannerCap(TwCap.ICAP_XRESOLUTION);
            Int32 resolution = Int32.Parse(capInfo.CurrentIntStr);

            // 获得空白页检测阈值
            capInfo = twSession.GetScannerCap(TwCap.ICAP_AUTODISCARDBLANKPAGES);
            intStr  = capInfo.CurrentIntStr;
            int blankImageSizeThreshold = 0;

            if (!Int32.TryParse(intStr, out blankImageSizeThreshold))
            {
                blankImageSizeThreshold = 0;
            }
            //获取传输模式
            TwMode mode = twSession.GetCurrentTransferMode();

            transferFileDelegate transferFileAction = null;                                //委托,记录不同传输模式下的单个文件传输函数

            switch (mode)
            {
            case TwMode.TWSX_FILE:
                transferFileAction = twSession.TransferSingleFileInFileMode;
                break;

            case TwMode.TWSX_NATIVE:
                transferFileAction = twSession.TransferSingleFileInNativeMode;
                break;

            default:
                break;
            }

            // 1:初始化GDI+
            Gdip.InitGDIPlus();
            int cnt = 0;

            scanResultList = new List <string>();

            //2:依次传输每个文件
            TwRC transferResult;                                            //每次传输的返回结果

            logger.Debug("开始传输文件: " + DateTime.Now);
            if (transferFileAction != null)
            {
                int count = 0;
                try
                {
                    do
                    {
                        logger.Debug("开始传输单个文件: count = " + count + ":" + DateTime.Now);
                        //传输单个文件
                        transferResult = transferFileAction(fileFormat, out fileSingleName, resolution, out msg);
                        twSession.EndXfer(out count);
                        logger.Debug("结束一次传输 : count = " + count + ",传输结果: " + transferResult + ":" + DateTime.Now);
                        //2.1:传输成功则检查文件大小
                        if (transferResult == TwRC.XferDone)
                        {
                            if (fileSingleName != null)
                            {
                                //A:判断读取的文件大小,零字节则不添加到列表中
                                FileInfo fileInfo = new FileInfo(fileSingleName);
                                if (fileInfo.Length > blankImageSizeThreshold && fileInfo.Length < userConfig.MaxSize)
                                {
                                    cnt++;
                                    scanResultList.Add(fileSingleName);
                                    logger.Debug("追加文件到列表,文件名: " + fileSingleName);
                                    //RaiseGetOnePageEvent(fileSingleName);
                                }
                                //B:否则删除文件
                                else
                                {
                                    fileInfo.Delete();
                                    if (fileInfo.Length <= blankImageSizeThreshold)
                                    {
                                        logger.Info("删除扫描结果文件,把他当作空白页。");
                                    }
                                    if (fileInfo.Length >= userConfig.MaxSize)
                                    {
                                        logger.Info("文件太大,删除扫描结果文件。");
                                    }
                                }
                            }
                            else
                            {
                                logger.Debug("文件名为null。");
                            }
                        }
                        //2.2:传输失败则跳出循环
                        else
                        {
                            if (count != 0) //如果扫描仪还有图像未传输,通知扫描仪清空
                            {
                                twSession.ResetScanner();
                            }
                            break;
                        }
                    } while (count != 0 && count != -2);

                    logger.Debug("结束循环 :" + DateTime.Now);

                    if (transferResult == TwRC.Failure)
                    {
                        MessageBox.Show("扫描失败:" + msg);
                    }
                    else
                    {
                        if (twSession.State >= TwState.OpenDS)
                        {
                            twSession.DisableDS();
                        }
                    }

                    if (transferResult == TwRC.TransferError)
                    {
                        MessageBox.Show("传输失败:" + msg);
                    }

                    if (transferResult == TwRC.BadValue)
                    {
                        MessageBox.Show("扫描仪当前设置不支持文件格式" + fileFormat + ",请重新设置");
                    }
                }
                #region 异常处理
                catch (ArgumentNullException e)
                {
                    logger.Error("参数为空异常,异常信息: " + e.Message);
                }
                catch (ArgumentException e)
                {
                    logger.Error("无效参数异常,异常信息: " + e.Message);
                }
                catch (System.Security.SecurityException e)
                {
                    logger.Error("安全性错误引发的异常,异常信息:" + e.Message);
                }
                catch (UnauthorizedAccessException e)
                {
                    logger.Error("IO错误或指定类型引发的安全性错误引发的异常,异常信息: " + e.Message);
                }
                catch (PathTooLongException e)
                {
                    logger.Error("路径太长引发的异常,异常信息: " + e.Message);
                }
                catch (NotSupportedException e)
                {
                    logger.Error("调用的方法不受支持或视图读取,查找或写入不支持调用功能的流引发的异常,异常信息: " + e.Message);
                }
                catch (IOException e)
                {
                    logger.Error("IO异常,异常信息: " + e.Message);
                }
                catch (Exception e)
                {
                    logger.Error("操作发生异常,异常信息: " + e.Message);
                }
                finally
                {
                    Gdip.ClearGDIPlus();
                }
                #endregion
            }

            //3:处理传输结果
        }