Example #1
0
 public TwainMessageFilter(ScanProfile settings, Twain tw, FTwainGui form)
 {
     this.settings   = settings;
     this.tw         = tw;
     this.form       = form;
     Bitmaps         = new List <ScannedImage>();
     form.Activated += FTwainGui_Activated;
 }
Example #2
0
 public TwainMessageFilter(ScanProfile settings, Twain tw, FTwainGui form, IScannedImageFactory scannedImageFactory)
 {
     this.settings = settings;
     this.tw = tw;
     this.form = form;
     this.scannedImageFactory = scannedImageFactory;
     Bitmaps = new List<IScannedImage>();
     form.Activated += FTwainGui_Activated;
 }
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
 public static List<ScannedImage> Scan(ScanProfile settings, ScanDevice device, IWin32Window pForm, IFormFactory formFactory)
 {
     var tw = new Twain();
     if (!tw.Init(pForm.Handle))
     {
         throw new DeviceNotFoundException();
     }
     if (!tw.SelectByName(device.ID))
     {
         throw new DeviceNotFoundException();
     }
     var form = formFactory.Create<FTwainGui>();
     var mf = new TwainMessageFilter(settings, tw, form);
     form.ShowDialog(pForm);
     return mf.Bitmaps;
 }
Example #5
0
        public static ScanDevice SelectDeviceUi()
        {
            var tw = new Twain();

            if (!tw.Init(Application.OpenForms[0].Handle))
            {
                throw new NoDevicesFoundException();
            }
            if (!tw.Select())
            {
                return(null);
            }
            var name = tw.GetCurrentName();

            return(name == null ? null : new ScanDevice(name, name));
        }
Example #6
0
        public static List <ScannedImage> Scan(ScanProfile settings, ScanDevice device, IWin32Window pForm, IFormFactory formFactory)
        {
            var tw = new Twain();

            if (!tw.Init(pForm.Handle))
            {
                throw new DeviceNotFoundException();
            }
            if (!tw.SelectByName(device.ID))
            {
                throw new DeviceNotFoundException();
            }
            var form = formFactory.Create <FTwainGui>();
            var mf   = new TwainMessageFilter(settings, tw, form);

            form.ShowDialog(pForm);
            return(mf.Bitmaps);
        }
Example #7
0
 public static ScanDevice SelectDeviceUI()
 {
     var tw = new Twain();
     if (!tw.Init(Application.OpenForms[0].Handle))
     {
         throw new NoDevicesFoundException();
     }
     if (!tw.Select())
     {
         return null;
     }
     string name = tw.GetCurrentName();
     if (name == null)
     {
         return null;
     }
     return new ScanDevice(name, name);
 }
Example #8
0
 public static List<ScanDevice> GetDeviceList()
 {
     var tw = new Twain();
     if (!tw.Init(Application.OpenForms[0].Handle))
     {
         throw new NoDevicesFoundException();
     }
     var result = new List<ScanDevice>();
     if (!tw.GetFirst())
     {
         return result;
     }
     do
     {
         string name = tw.GetCurrentName();
         result.Add(new ScanDevice(name, name));
     } while (tw.GetNext());
     return result;
 }
Example #9
0
        public static List <ScanDevice> GetDeviceList()
        {
            var tw = new Twain();

            if (!tw.Init(Application.OpenForms[0].Handle))
            {
                throw new NoDevicesFoundException();
            }
            var result = new List <ScanDevice>();

            if (!tw.GetFirst())
            {
                return(result);
            }
            do
            {
                string name = tw.GetCurrentName();
                result.Add(new ScanDevice(name, name));
            } while (tw.GetNext());
            return(result);
        }
Example #10
0
        public static void Scan(ScanProfile settings, ScanDevice device, IWin32Window pForm, IFormFactory formFactory, ScannedImageSource.Concrete source)
        {
            var tw = new Twain();

            if (!tw.Init(pForm.Handle))
            {
                throw new DeviceNotFoundException();
            }
            if (!tw.SelectByName(device.ID))
            {
                throw new DeviceNotFoundException();
            }
            var form = formFactory.Create <FTwainGui>();
            var mf   = new TwainMessageFilter(settings, tw, form);

            form.ShowDialog(pForm);
            foreach (var b in mf.Bitmaps)
            {
                source.Put(b);
            }
        }
Example #11
0
        public static void Scan(ScanProfile settings, ScanDevice device, IWin32Window pForm, IFormFactory formFactory, ScannedImageSource.Concrete source)
        {
            var tw           = new Twain();
            var windowHandle = (Invoker.Current as Form)?.Handle ?? pForm.Handle;

            if (!tw.Init(windowHandle))
            {
                throw new DeviceNotFoundException();
            }
            if (!tw.SelectByName(device.Id))
            {
                throw new DeviceNotFoundException();
            }
            var form = Invoker.Current.InvokeGet(formFactory.Create <FTwainGui>);
            var mf   = new TwainMessageFilter(settings, tw, form);

            Invoker.Current.Invoke(() => form.ShowDialog(pForm));
            foreach (var b in mf.Bitmaps)
            {
                source.Put(b);
            }
        }