Example #1
2
        private List<Scaner> GetScanersList()
        {
            List<Scaner> ls = new List<Scaner>();
            Scaner s;
            try
            {
                Twain _twain = new Twain(_wh);
                if (_twain.SourceNames.Count != 0)
                {
                    _twain.SelectSource();
                    s = new Scaner(_twain.DefaultSourceName, EnumScanerType.Twain, _wh);
                    ls.Add(s);
                }
            }
            catch (TwainException) { }
            List<string> devices = WIAScanner.GetDevices();
            foreach (string device in devices)
            {
                s = new Scaner(device, EnumScanerType.WIA, _wh);
                ls.Add(s);

            }
            s = new Scaner("Изображение из файла", EnumScanerType.File, _wh);
            ls.Add(s);
            return ls;
        }
Example #2
1
        /// <summary>
        /// ScanCard instance is the start of a new scan of an insurance card and allow for the front and back side of the insurance card scanned to be added to the Allscripts EHR
        /// </summary>
        public ScanCard()
        {
            InitializeComponent();

            Nullable<int> i = ScannerSettings.ResolutionSettings.BrightLevel;
            if (i.HasValue)
            {
                imgVwrFront.Brightness = i.Value;
                imgVwrBack.Brightness = i.Value;
            }

            frontTwain = new Twain(new WinFormsWindowMessageHook(this));
            frontTwain.TransferImage += new EventHandler<TransferImageEventArgs>(FrontTwainTransferImage);
            frontTwain.ScanningComplete += new EventHandler<ScanningCompleteEventArgs>(FrontTwain_ScanningComplete);

            backTwain = new Twain(new WinFormsWindowMessageHook(this));
            backTwain.TransferImage += new EventHandler<TransferImageEventArgs>(BackTwain_TransferImage);
            backTwain.ScanningComplete += new EventHandler<ScanningCompleteEventArgs>(BackTwain_ScanningComplete);

            // Create a simple tray menu with only one item.
            trayMenu = new ContextMenu();
            trayMenu.MenuItems.Add("New Scan", ReScanBothToolStripMenuItemClick);
            trayMenu.MenuItems.Add("-");
            trayMenu.MenuItems.Add("Exit", OnExit);

            // Create a tray icon. In this example we use a
            // standard system icon for simplicity, but you
            // can of course use your own custom icon too.
            trayIcon = new NotifyIcon();
            trayIcon.Text = "Allscripts Insurance Card Scan";
            trayIcon.Icon = this.Icon;

            // Add menu to tray icon and show it.
            trayIcon.ContextMenu = trayMenu;
            trayIcon.Visible = true;
        }
Example #3
0
        public Window1()
        {
            InitializeComponent();

            Loaded += delegate
            {
                _twain = new Twain(new WpfWindowMessageHook(this));
                _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
                {
                    if (args.Image != null)
                    {
                        resultImage = args.Image;
                        IntPtr hbitmap = new Bitmap(args.Image).GetHbitmap();
                        MainImage.Source = Imaging.CreateBitmapSourceFromHBitmap(
                                hbitmap,
                                IntPtr.Zero,
                                Int32Rect.Empty,
                                BitmapSizeOptions.FromEmptyOptions());
                        Gdi32Native.DeleteObject(hbitmap);
                    }
                };
                _twain.ScanningComplete += delegate
                {
                    IsEnabled = true;
                };

                var sourceList = _twain.SourceNames;
                ManualSource.ItemsSource = sourceList;

                if (sourceList != null && sourceList.Count > 0)
                    ManualSource.SelectedItem = sourceList[0];
            };
        }
Example #4
0
        public TwainDotNetSource(int i, string sourceName, TwainDotNet.Twain twain, WindowsMessageLoopThread windowsMessageLoop)
        {
            Name  = sourceName;
            Index = i;
            _windowsMessageLoop = windowsMessageLoop;
            _scanCompleteEvent  = new ManualResetEvent(false);
            _twain = twain;
            _log   = LogManager.GetLogger(typeof(TwainDotNetSource));

            _log.Debug(string.Format("Created TWAIN name={0}, index={1}", sourceName, i));
        }
		public TwainDotNetSource(int i, string sourceName, TwainDotNet.Twain twain, WindowsMessageLoopThread windowsMessageLoop)
		{
			Name = sourceName;
			Index = i;
			_windowsMessageLoop = windowsMessageLoop;
			_scanCompleteEvent = new ManualResetEvent(false);
			_twain = twain;
			_log = LogManager.GetLogger(typeof (TwainDotNetSource));

			_log.Debug(string.Format("Created TWAIN name={0}, index={1}", sourceName, i));
		}
Example #6
0
        public MainForm()
        {
            InitializeComponent();

            _twain = new Twain(new WinFormsWindowMessageHook(this));
            _twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
            {
                if (args.Image != null)
                {
                    pictureBox1.Image = args.Image;

                    widthLabel.Text = "Width: " + pictureBox1.Image.Width;
                    heightLabel.Text = "Height: " + pictureBox1.Image.Height;
                }
            };
            _twain.ScanningComplete += delegate
            {
                Enabled = true;
            };
        }
Example #7
0
        public Scaner(string name, EnumScanerType type, WinFormsWindowMessageHook wh)
        {
            arg = new EventArgs();
            _name = name.Trim();
            _type = type;
            _wh = wh;
            if (_type == EnumScanerType.Twain)
            {
                try
                {
                    _twain = new Twain(_wh);
                    _twain.TransferImage += new EventHandler<TransferImageEventArgs>(_twain_TransferImage);
                    _twain.ScanningComplete += new EventHandler<ScanningCompleteEventArgs>(_twain_ScanningComplete);
                    _twain.SelectSource(_name);
                }
                catch
                {
                    _type = EnumScanerType.File;
                }

            }
        }
Example #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Institution institution = DozpController.GetInstitution();
            this.CatalogueComboBox.ItemsSource = (institution != null ? institution.Catalogues : null);

            Twain twain = new Twain(new WpfWindowMessageHook(this));
            this.ScannerSourceNameComboBox.ItemsSource = twain.SourceNames;

            this.AppLoggingButton.IsEnabled = File.Exists(Logger.FileName);
        }
Example #9
0
        private Scan InitTwain(JObject request, JObject reply)
        {
            log.Debug("processing 'init_twain' action");

            if (twain != null) return ReportException(request, reply, "twain already initialized", "twain already initialized");

            twainException = null;
            form.TopMost = true;
            form.Invoke((MethodInvoker)delegate
                {
                    try
                    {
                        log.Debug("form delegate: create twain");
                        twain = new Twain(hook);

                        log.Debug("form delegate: set twain transfer image delegate");
                        twain.TransferImage += delegate(Object sender, TransferImageEventArgs args)
                        {
                            log.Debug("twain transfer image delegate");
                            if (args.Image != null)
                            {
                                imageUuid = System.Guid.NewGuid().ToString();
                                image = new System.IO.MemoryStream();
                                // !!!! TODO !!!! add here parameters that allow user to choose image format ////
                                ///!!!! TODO !!!! and format properties using imageAcquirerequest ////
                                args.Image.Save(image, System.Drawing.Imaging.ImageFormat.Jpeg);
                                imageType = "image/jpeg";
                                log.Debug("image transfer complete");
                            }
                            else
                            {
                                log.Debug("no image to transfer");
                            }
                            imageTransferred.Set();

                        };
                        log.Debug("form delegate: set twain scanning complete delegate");
                        twain.ScanningComplete += delegate
                        {
                            log.Debug("scanning complete delegate");
                            imageAcquired.Set();
                        };

                        log.Debug("form delegate: finished");
                    }
                    catch (Exception ex)
                    {
                        log.Error("twain exception", ex);
                        twainException = ex;
                    }
                });
            if (twainException != null) return ReportException(request, reply, twainException.Message, twainException.ToString());
            reply.Add("ok", true);

            return SendReply(reply);
        }
Example #10
0
        void ResetControls()
        {
            this.autostartCheckBox.Checked = Properties.Settings.Default.server_autostart;
            this.startMinimizedCheckBox.Checked = Properties.Settings.Default.start_minimized;
            this.portUpDown.Value = Properties.Settings.Default.port;
            this.xUpDown.Value = Properties.Settings.Default.x;
            this.yUpDown.Value = Properties.Settings.Default.y;
            this.wUpDown.Value = Properties.Settings.Default.w;
            this.hUpDown.Value = Properties.Settings.Default.h;
            if (this.encodingComboBox.Items.Contains(Properties.Settings.Default.encode)) this.encodingComboBox.SelectedItem = Properties.Settings.Default.encode;
            this.adfCheckBox.Checked = Properties.Settings.Default.useADF;
            this.pdfCheckBox.Checked = Properties.Settings.Default.pdf;

            if (this.dpiComboBox.Items.Contains("" + Properties.Settings.Default.dpi)) this.dpiComboBox.SelectedItem = "" + Properties.Settings.Default.dpi;
            else this.dpiComboBox.SelectedItem = "300";

            if (Properties.Settings.Default.colour == ColourSetting.BlackAndWhite) this.blackAndWhiteRadioButton.Checked = true;
            else if (Properties.Settings.Default.colour == ColourSetting.GreyScale) this.greyscaleRadioButton.Checked = true;
            else this.colourRadioButton.Checked = true;

            this.sourceComboBox.Items.Add("");
            bool processed = false;
            this.twain = new Twain(new WinFormsWindowMessageHook(this));
            foreach (string name in this.twain.SourceNames)
            {
                this.sourceComboBox.Items.Add(name);
                if (name.Equals(Properties.Settings.Default.twain_source))
                {
                    this.sourceComboBox.SelectedItem = name;
                    processed = true;
                }
            }
            if (!processed)
            {
                Properties.Settings.Default.twain_source = "";
            }
            this.twain.TransferImage += new EventHandler<TransferImageEventArgs>(TransferImage);
            this.twain.ScanningComplete += new EventHandler<ScanningCompleteEventArgs>(ScanningComplete);
        }
Example #11
0
        public MainWindow()
        {
            InitializeComponent();
            InitializeShortcuts();

            try
            {
                Version version = Assembly.GetExecutingAssembly().GetName().Version;
                string appName = Properties.Resources.ApplicationName;
                string fullName = AuthController.UserIdentity.LoginUser.FullName;
                this.RibbonWindow.Title = String.Format("{0} v{1}.{2}.{3} [{4}]", appName, version.Major, version.Minor, version.Revision, fullName);
                this.WindowState = (Settings.Default.MainWindowMax ? WindowState.Maximized : WindowState.Normal);
                this.Topmost = Settings.Default.AppAlwaysOnTop;

                if (Settings.Default.AppLogging)
                {
                    Logger.Open();
                    Logger.Log(String.Format("\n{0}, Version:{1}.{2}.{3} Build:{4}, UserName:{5}, MachineName:{6}", appName, version.Major, version.Minor, version.Revision, version.Build, fullName, Environment.MachineName));
                }

                this.ScannerColorModeCoverCategory.ItemsSource = Enumeration.GetList(typeof(ColourSetting));
                this.ScannerColorModeContentsCategory.ItemsSource = Enumeration.GetList(typeof(ColourSetting));
                this.ScannerResolutionCoverCategory.ItemsSource = ScanImage.RESOLUTIONS;
                this.ScannerResolutionContentsCategory.ItemsSource = ScanImage.RESOLUTIONS;

                this.DataContext = this;

                Loaded += delegate
                {
                    try
                    {
                        _twain = new Twain(new WpfWindowMessageHook(this));
                        _twain.TransferImage += TwainTransferImage;
                        _twain.ScanningComplete += TwainScanningComplete;
                        foreach (var name in _twain.SourceNames)
                        {
                            RibbonMenuItem item = new RibbonMenuItem();
                            item.Style = (LayoutRoot.Resources["RibbonMenuItemCheckable"] as Style);
                            item.IsChecked = (name == Settings.Default.ScannerSourceName);
                            item.Header = name;
                            item.Click += ScannerMenuItem_Click;
                            this.ScannerButton.Items.Add(item);
                        }
                    }
                    catch (TwainException tex)
                    {
                        string message = tex.Message + "\n[Pravdepodobně není nainstalován ovladač pro skener]";
                        MessageBox.Show(message, "TWAIN", MessageBoxButton.OK, MessageBoxImage.Exclamation);
                        Logger.Log(String.Format("TWAIN: {0}", message));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
                        Logger.Log(String.Format("ERROR: {0}", ex.Message));
                    }
                };
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, ex.Source, MessageBoxButton.OK, MessageBoxImage.Error);
                Logger.Log(String.Format("ERROR: {0}", ex.Message));
            }
        }