Visualization of digitized image by scanner C #

Questions, comments and suggestions concerning VintaSoft Twain .NET SDK.

Moderator: Alex

Post Reply
nicovillas
Posts: 1
Joined: Fri May 26, 2017 4:52 pm

Visualization of digitized image by scanner C #

Post by nicovillas » Wed Apr 10, 2019 8:16 pm

Hello
I am new to this forum, but I would like to know a little more about the advantages of Vintasoft. Develop a Windows Forms application based on the C # language using the Vintasoft library, the scanner used is a Kodak i2000, I need to be able to visualize the image in a picture box of the current sheet that is being scanned, which I could not integrate completely. In addition the scanner has the function of Perfect Page which allows to automatically rotate the digitized image that function does not count if Vintasoft without using the ShowUI. Attentive to your help, I will leave my code of my functions.

Code: Select all

private void btnDigitaliza_Click(object sender, EventArgs e)
        {
            btnDigitaliza.Enabled = false;
            btnSalir.Enabled = false;

            deviceManager.IsTwain2Compatible = true;
            deviceManager.Open();
            string deviceName = "KODAK Scanner: i900";
            device = deviceManager.Devices.Find(deviceName);
            if (device == null)
            {
                _isImageAcquiring = false;
                MessageBox.Show("El driver del dispositivo " + deviceName + " no se encuentra en el sistema, favor realizar la instalación del driver", "Administrador de Dispositivos");
                btnDigitaliza.Enabled = true;
                btnSalir.Enabled = true;
            }
            else
            {
                device.ShowUI = false;
                device.DisableAfterAcquire = true;
                device.Open();
                device.DocumentFeeder.DuplexEnabled = true;
                device.TransferMode = TransferMode.Memory;
                device.PixelType = PixelType.Gray;
                device.UnitOfMeasure = UnitOfMeasure.Inches;
                device.Resolution = new Resolution(300.0f, 300.0f);

                ///Nombre del documento
                string nEquipo = Environment.MachineName;
                string fecha = (DateTime.Now).ToString("yyyyMMdd_HHmmss");
                string nDocumento="Hipotecario_"+nEquipo+"_"+fecha+".pdf";
                ///
                ///Crear directorio para almacenar archivos
                string directorio = @"C:\DocumentoEphesoft";
                if (!System.IO.Directory.Exists(directorio))
                {
                    System.IO.Directory.CreateDirectory(directorio);
                }
                ///
                string pPDF = System.IO.Path.Combine(directorio, nDocumento);

                if (device.HasFeeder)
                {
                    device.DocumentFeeder.Enabled = true;
                    device.XferCount = -1;
                    if (device.DocumentFeeder.DuplexMode != DuplexMode.None)
                    {
                        device.DocumentFeeder.DuplexEnabled = true;
                        if (device.DocumentFeeder.PaperDetectable)
                        {
                            if (device.DocumentFeeder.Loaded)
                            device.Acquire();
                        }
                    }
                    else
                    {
                        device.Acquire();
                    }
                }
                AcquireModalState acquireModalState = AcquireModalState.None;
                AcquiredImage acquiredImage;

                do
                {
                    acquireModalState = device.AcquireModal();
                    switch (acquireModalState)
                    {
                        case AcquireModalState.ImageAcquired:
                            // obtener una referencia de la imagen adquirida por el dispositivo
                            acquiredImage = device.AcquiredImage;
                            // detectar bordes
                            ProcessAcquiredImage(acquiredImage);
                            // agregar una imagen que no sea blanca al multipagina TIFF
                            // (0.01f) = 1%
                            if (!acquiredImage.IsBlank(0.03f))
                                acquiredImage.Save(pPDF);
                            // Disponer de la imagen adquirida
                            acquiredImage.Dispose();
                            break;
                    }
                }
                while (acquireModalState != AcquireModalState.None);
                device.Close();
                deviceManager.Close();

                string documento = Path.Combine(directorio, nDocumento);
                if (File.Exists(pPDF))
                {
                    string batch = "BC37";
                    WebService ws = new WebService();
                    string data=ws.subirDocumento(batch, pPDF);
                    //Delimitador de respuesta del web service
                    char delimitador = '_';
                    string[] words = data.Split(delimitador);
                    string codigo = words[0];
                    string batchid = words[1];
                    string msjerror = words[2];
                    //Validacion de la respuesta y luego entregarla al usuario
                    if (codigo == "200")
                    {
                        txtMensaje.Text = "Batch " + batch + ": Lote cargado correctamente en Ephesoft";
                    }
                    else if (codigo == "403")
                    {
                        txtMensaje.Text = "Acceso no autorizado al sistema de Ephesoft. "+msjerror;
                    }
                    else if (codigo == "422")
                    {
                        txtMensaje.Text = "Entidad del documento no procesable. "+msjerror;
                    }
                    else if (codigo == "500")
                    {
                        txtMensaje.Text = "Error interno del servidor. "+msjerror;
                    }
                    else
                    {
                        txtMensaje.Text = "Favor digitalice nuevamente el documento";
                    }
                    txtMensaje.Text = "El archivo requerido se pudo enviar Ephesoft";
                    txtMensaje.Visible = true;
                }
                else
                {
                    txtMensaje.Text = "El archivo requerido no se pudo digitalizar, por favor intente nuevamente";
                    txtMensaje.Visible = true;
                }

                btnSalir.Enabled = true;
                btnDigitaliza.Enabled = true;
            }
        }

Alex
Site Admin
Posts: 1638
Joined: Thu Jul 10, 2008 2:21 pm

Re: Visualization of digitized image by scanner C #

Post by Alex » Thu Apr 11, 2019 3:46 pm

Hello,

In your code you are using together the Device.Acquire and Device.AcquireModal method - this is big mistake, do not do this and use Device.Acquire or Device.AcquireModal method.

VintaSoft Twain .NET SDK has on-line documentation, which describes how to work with scanner. On-line documentation is available here: https://www.vintasoft.com/docs/vstwain-dotnet/

Please read how to acquire images from scanner asynchronously here: https://www.vintasoft.com/docs/vstwain- ... ously.html

Please read how to acquire images from scanner synchronously here: https://www.vintasoft.com/docs/vstwain- ... ously.html

I need to be able to visualize the image in a picture box of the current sheet that is being scanned
Also SDK has WinForms demos, which demonstrate how to acquire images from scanner and preview images in WinForms application. Please read about available demos here: https://www.vintasoft.com/docs/vstwain- ... rview.html

the scanner has the function of Perfect Page which allows to automatically rotate the digitized image that function does not count if Vintasoft without using the ShowUI
TWAIN driver provides custom functionality using custom capabilities. Please read how to get information about custom capabilities here: https://www.vintasoft.com/forums/viewto ... =25&t=2366

Best regards, Alexander

Post Reply