Example #1
0
        public Scaner()
        {
            InitializeComponent();

            tw = new Twain();
            tw.Init(this.Handle);
        }
Example #2
0
 public void ScanEnd()
 {
     if (tw != null)
     {
         EndingScan();
         tw.CloseSrc();
         tw = null;
     }
 }
Example #3
0
        public TwCapability(TwCap cap, short sval)
        {
            Cap     = (short)cap;
            ConType = (short)TwOn.One;
            Handle  = Twain.GlobalAlloc(0x42, 6);
            IntPtr pv = Twain.GlobalLock(Handle);

            Marshal.WriteInt16(pv, 0, (short)TwType.Int16);
            Marshal.WriteInt32(pv, 2, sval);
            Twain.GlobalUnlock(Handle);
        }
Example #4
0
 /// <summary>
 /// Clean up any resources being used.
 /// </summary>
 protected override void Dispose(bool disposing)
 {
     Application.RemoveMessageFilter(this);
     if (tw != null)
     {
         tw.CloseSrc();
         tw = null;
     }
     if (disposing)
     {
         if (components != null)
         {
             components.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Example #5
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == WM_CREATE)
            {
                if (tw == null)
                {
                    tw = new Twain();
                    tw.Init(this.Handle);
                }
                else
                {
                    tw.Init(this.Handle);
                }
            }

            base.WndProc(ref m);
        }
Example #6
0
        bool IMessageFilter.PreFilterMessage(ref Message m)
        {
            if (m.HWnd != this.Handle)
            {
                return(false);
            }
            TwainCommand cmd = tw.PassMessage(ref m);

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

            switch (cmd)
            {
            case TwainCommand.Failure:
            case TwainCommand.CloseRequest:
            case TwainCommand.CloseOk:
            {
                EndingScan();
                tw.CloseSrc();
                OnDialogClose(currentScanType, callback);
                break;
            }

            case TwainCommand.DeviceEvent:
            {
                break;
            }

            case TwainCommand.TransferReady:
            {
                ArrayList pics = tw.TransferPictures();
                EndingScan();
                tw.CloseSrc();
                if (pics != null)
                {
                    List <Bitmap> bitmaps = new List <Bitmap>();
                    for (int n = 0; n < pics.Count; n++)
                    {
                        IntPtr img = (IntPtr)pics[n];
                        try
                        {
                            IntPtr bmpptr = Twain.GlobalLock(img);
                            Bitmap b      = null;
                            try
                            {
                                b = DibToImage.WithScan0(bmpptr);
                            }
                            catch { }
                            if (b != null)
                            {
                                bitmaps.Add(b);
                            }
                        }
                        catch (Exception ex)
                        {
                            Tiff.LibTiffHelper.WriteToLog(ex);
                        }
                        finally
                        {
                            Twain.GlobalFree(img);
                        }
                        pics[n] = null;
                    }
                    if (bitmaps.Count > 0)
                    {
                        OnImagesReceived(bitmaps, currentScanType, callback);
                    }
                }
                break;
            }
            }
            return(true);
        }