Esempio n. 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
            String       Archivo       = "D:\\EJEMPLO_ESCANEO_012";
            //CommonDialogClass wiaDiag = new CommonDialogClass();
            ICommonDialog wiaDiag = new WIA.CommonDialog();

            WIA.ImageFile wiaImage = null;
            wiaImage = wiaDiag.ShowAcquireImage(WiaDeviceType.UnspecifiedDeviceType, WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality,
                                                wiaFormatJPEG, true, true, false);
            WIA.Vector vector = wiaImage.FileData;
            pictureBox1.Image = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));

            Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));

            i.Save(Archivo + ".TIFF");

            PdfSharp.Pdf.PdfDocument doc = new PdfSharp.Pdf.PdfDocument();
            doc.Pages.Add(new PdfSharp.Pdf.PdfPage());
            PdfSharp.Drawing.XGraphics xgr = PdfSharp.Drawing.XGraphics.FromPdfPage(doc.Pages[0]);
            PdfSharp.Drawing.XImage    img = PdfSharp.Drawing.XImage.FromFile(Archivo + ".TIFF");

            xgr.DrawImage(img, 0, 0);
            doc.Save(Archivo + ".PDF");
            doc.Close();
        }
Esempio n. 2
0
        private void digitalizarToolStripButton_Click(object sender, EventArgs e)
        {
            const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
            var          wiaDiag       = new WIA.CommonDialog();

            // instanciando a WiaImagem
            WIA.ImageFile wiaImage = null;
            //objeto criado para fins de fazer scanear varios documentos de uma vez
            int i = 1;
            //objeto criado para fins de fazer scanear varios documentos de uma vez
            object index = 1;

            // capturando a imgaem scaneada e abrindo o pop-up do scanner
            wiaImage = wiaDiag.ShowAcquireImage(
                WiaDeviceType.UnspecifiedDeviceType,
                WiaImageIntent.GrayscaleIntent,
                WiaImageBias.MaximizeQuality,
                wiaFormatJPEG, true, true, false);
            //pegando o WiaImage e vetorizando
            WIA.Vector vector = wiaImage.FileData;
            // carregando a imagem em memoria
            Image img = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));

            img.Save("C:/imagem" + i + ".jpg");
        }
Esempio n. 3
0
        public BitmapSource InMemoryConvertScannedImage(ImageFile imageFile)
        {
            if (imageFile == null)
            {
                return(null);
            }

            try
            {
                WIA.Vector vector = imageFile.FileData;

                if (vector != null)
                {
                    byte[] bytes = vector.get_BinaryData() as byte[];

                    if (bytes != null)
                    {
                        var ms = new MemoryStream(bytes);
                        return(BitmapFrame.Create(ms));
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message, ex);
            }

            return(null);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";

            WIA.CommonDialog wiaDiag  = new WIA.CommonDialog();
            WIA.ImageFile    wiaImage = null;
            wiaImage = wiaDiag.ShowAcquireImage(WiaDeviceType.UnspecifiedDeviceType, WiaImageIntent.GrayscaleIntent,
                                                WiaImageBias.MaximizeQuality, wiaFormatJPEG, true, true, false);
            WIA.Vector vector = wiaImage.FileData;
            Image      i      = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));

            pictureBox.Image = i;
        }
Esempio n. 5
0
        public List <Image> start()
        {
            List <Image> imageLost = new List <Image>();

            WIA.CommonDialog dialog = new WIA.CommonDialog();
            WIA.Device       device = dialog.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType);
            WIA.Items        items  = dialog.ShowSelectItems(device);
            WIA.ImageFile    image  = null;
            dialog = new WIA.CommonDialog();
            foreach (WIA.Item item in items)
            {
                while (true)
                {
                    Console.WriteLine(device.Commands);

                    try
                    {
                        if (stop == true)
                        {
                            image = null;
                            stop  = false;
                        }
                        else
                        {
                            image = (WIA.ImageFile)dialog.ShowTransfer(item, "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}", false);
                        }
                        if ((image != null) && (image.FileData != null))
                        {
                            WIA.Vector vector = image.FileData;
                            imageLost.Add(Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData())));
                        }
                    }
                    catch (System.Runtime.InteropServices.COMException)
                    {
                        return(imageLost);
                    }
                    finally
                    {
                        if (image != null)
                        {
                            Marshal.FinalReleaseComObject(image);
                        }
                    }
                }
            }
            return(imageLost);
        }
        private void btnScan_Click(object sender, EventArgs e)
        {
            try
            {
                WIA.CommonDialog dialog = new WIA.CommonDialog();

                ImageFile scannedImage = null;
                scannedImage = dialog.ShowAcquireImage(
                    WiaDeviceType.ScannerDeviceType,
                    WiaImageIntent.UnspecifiedIntent,
                    WiaImageBias.MaximizeQuality,
                    FormatID.wiaFormatPNG,
                    true, true, false);
                if (scannedImage != null)
                {
                    WIA.Vector vector = scannedImage.FileData;
                    byte[]     b      = (byte[])vector.get_BinaryData();

                    System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(b));
                    pictureBox1.Image  = img;
                    pictureBox1.Height = img.Height;
                    pictureBox1.Width  = img.Width;
                    pictureBox1.Image  = img;
                }
            }catch (Exception ex)
            {
                Scanner   scanner = new Scanner();
                ArrayList list    = scanner.ADFScan();
                if (list.Count <= 0)
                {
                    MessageBox.Show("خطا در دستیابی به اسکنر ، لطفا از وصل بودن کابلهای اسکنر اطمینان حاصل کنید" + "\n" + ex.Message);
                }
                else
                {
                    WIA.Vector vector = ((ImageFile)list[0]).FileData;
                    byte[]     b      = (byte[])vector.get_BinaryData();

                    System.Drawing.Image img = System.Drawing.Image.FromStream(new System.IO.MemoryStream(b));
                    pictureBox1.Image  = img;
                    pictureBox1.Height = img.Height;
                    pictureBox1.Width  = img.Width;
                    pictureBox1.Image  = img;
                }
            }
        }
Esempio n. 7
0
 public System.Drawing.Image Scann()
 {
     try
     {
         ImageFile imageFile = dlg.ShowAcquireImage(oDevice.Type,
                                                    WiaImageIntent.GrayscaleIntent,
                                                    WiaImageBias.MinimizeSize,
                                                    "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", false, false, false);
         WIA.Vector           vector = imageFile.FileData;
         System.Drawing.Image i      = System.Drawing.Image.FromStream(new
                                                                       System.IO.MemoryStream((byte[])vector.get_BinaryData()));
         return(i);
     }
     catch (Exception)
     {
         System.Windows.Forms.MessageBox.Show("SE PERDIO LA CONEXIÓN");
         this.mensaje = 1;
         return(null);
     }
 }
Esempio n. 8
0
        private void goScan()
        {
            try
            {
                WIA.ImageFile        image     = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);
                List <WIA.ImageFile> imageList = new List <ImageFile>();

                WIA.Vector vector = image.FileData;
                Image      img    = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
                if (img.Width < img.Height)
                {
                    img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                }

                images.Add(img);
                return;
            }
            catch (Exception)
            {
                //throw exc;
                return;
            }
        }
Esempio n. 9
0
        public Image Start()
        {
            WIA.ImageFile wiaImage = null;

            wiaImage = wiaDiag.ShowAcquireImage(
                WiaDeviceType.ScannerDeviceType,
                WiaImageIntent.TextIntent,
                WiaImageBias.MaximizeQuality,
                ImageFormat.wiaFormatTIFF,
                true,
                true,
                true
                );
            return(null);

            if (wiaImage != null)
            {
                WIA.Vector vector = wiaImage.FileData;
                Image      image  = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
                wiaImage.SaveFile("d:\\www.jpg");
                return(image);
            }
            return(null);
        }
Esempio n. 10
0
        public string scanv2()
        {
            string rutaImagen    = "";
            string nombreAdjunto = "";

            System.Drawing.Image i = null;
            try
            {
                device = dialogo.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
                ImageFile imageFile = dialogo.ShowAcquireImage(device.Type,
                                                               WiaImageIntent.GrayscaleIntent,
                                                               WiaImageBias.MinimizeSize,
                                                               "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", false, false, false);
                WIA.Vector vector = imageFile.FileData;

                DateTime fecha = DateTime.Now;
                nombreAdjunto = "scan_" + fecha.Day.ToString()
                                + fecha.Month.ToString()
                                + fecha.Year.ToString()
                                + "_" + fecha.Hour.ToString()
                                + fecha.Minute.ToString()
                                + fecha.Second.ToString()
                                + fecha.Millisecond.ToString()
                                + ".jpeg";
                rutaImagen = ClsGlobals.rutaAdjuntos + nombreAdjunto;


                if (System.IO.File.Exists(rutaImagen))
                {
                    System.IO.File.Delete(rutaImagen);
                }
                try
                {
                    // Se crea el directorio si no existe para almacenar los adjunntos
                    if (Directory.Exists(ClsGlobals.rutaAdjuntos))
                    {
                        DirectoryInfo di = Directory.CreateDirectory(ClsGlobals.rutaAdjuntos);
                    }
                    imageFile.SaveFile(rutaImagen);
                }
                catch (Exception ex)
                {
                    ClsHelper.erroLog(ex);
                }
                i = System.Drawing.Image.FromStream(new
                                                    System.IO.MemoryStream((byte[])vector.get_BinaryData()));
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == -2145320939)
                {
                    ClsHelper.MensajeSistema("No se encontro dispositivo conectado...");
                }
                else
                {
                    ClsHelper.erroLog(ex);
                }
            }
            catch (Exception)
            {
                ClsHelper.MensajeSistema("No se completo la operación...");
            }
            return(nombreAdjunto);
        }