Esempio n. 1
0
        public cBaseTwainScan(Form winForm)
        {
            ActiveForm            = winForm;
            _twain                = new Twain(new WinFormsWindowMessageHook(winForm));
            DJScanCompletList     = new List <string>();
            DJOneScanList         = new List <string>();
            _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
            {
                if (args.Image != null)
                {
                    string img = DJScanPath + DateTime.Now.ToString(@"\" + DJScanTitle + "yyMMddHHmmssff") + ".jpg";
                    args.Image.Save(img, System.Drawing.Imaging.ImageFormat.Jpeg);
                    DJImageProcess.EncryptJpg(img, DJJpgEncodeLevel, DJImgEncrypt);
                    //DJScanCompletList.Add(img);
                    DJOneScanList.Add(img);
                }
            };
            _twain.ScanningComplete += delegate
            {
                ResetImgToAB(DJOneScanList);
                DJScanCompletList.AddRange(DJOneScanList);

                winForm.Enabled = true;
                winForm.Activate();
                ScanComplete(winForm);
                //ScanComplete.Invoke(winForm);
                DJOneScanList.Clear();
            };
        }
Esempio n. 2
0
        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:
            {
                logger.Error("BaseScan.(DeviceEvent)裝置錯誤");
                //Console.WriteLine("DeviceEvent");
                break;
            }

            case TwainCommand.Null:
            {
                //logger.Error("BaseScan.(null) 正常等待");

                break;
            }

            case TwainCommand.Failure:
            {
                MessageBox.Show("設置錯誤");
                logger.Error("BaseScan.設置錯誤");
                EndingScan();
                tw.CloseSrc();
                break;
            }

            case TwainCommand.TransferReady:
            {
                #region 立即存檔
                logger.Info("BaseScan.1.已取得圖檔,存入指定路徑");
                DJScanCompletList = tw.TransferePicturesSaveImmediate(DJScanPath, DJScanTitle);
                EndingScan();
                tw.CloseSrc();
                #endregion

                switch (DJImageFormat)
                {
                case "jpg":
                    logger.Info("BaseScan.2.jpg 轉換");
                    DJScanCompletList = DJImageProcess.TransBmpToJpg(DJScanCompletList, DJJpgEncodeLevel, DJImgEncrypt);
                    logger.Info("BaseScan.2.jpg 轉換 ok");
                    break;

                default:
                    break;
                }

                logger.Info("BaseScan.3.21.送出完成委派");
                OnScanComplete(this);
                logger.Info("BaseScan.3.3.送完完成委派");
                break;
            }

            default:
                Console.WriteLine(cmd.ToString());
                break;
            }

            return(true);
        }