Esempio n. 1
1
        private const double Width = 8.27; // in inches.

        #endregion Fields

        #region Methods

        /// <summary>
        /// Aquire an image from the systems default scanner.
        /// </summary>
        /// <returns>byte array of the image.</returns>
        public static byte[] AquireImage()
        {
            var wiaDlg = new CommonDialog();
            var wiaDevice = wiaDlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType);

            if (wiaDevice.Items.Count == 1)
            {
                var scanner = wiaDevice.Items[1];

                //scanner.Properties["6146"].set_Value(1);
                scanner.Properties["6147"].set_Value(Dpi); // Horizontal resolution.
                scanner.Properties["6148"].set_Value(Dpi); // Vertical resolution.
                scanner.Properties["6151"].set_Value((int)(Dpi * Width)); // Horizontal extent.
                scanner.Properties["6152"].set_Value((int)(Dpi * Height)); // Vertical extent.
                //wiaDevice.Properties[4170].set_Value(1);

                /*var image =
                    wiaDlg.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent,
                        WiaImageBias.MaximizeQuality, FormatID.wiaFormatBMP, true, false, false);*/

                //scanner.Properties.Item
                var image = (ImageFile)wiaDlg.ShowTransfer(scanner, FormatID.wiaFormatJPEG);
                //var image = (ImageFile)scanner.Transfer();
                return (byte[]) image.FileData.get_BinaryData();
            }

            return null;
        }
Esempio n. 2
0
        public Scanner GetScanner(bool showDevicesDialog)
        {
            Scanner scanner = null;

            WrapCOMError(() =>
            {
                // ReSharper disable once RedundantArgumentDefaultValue
                var scannerDevice = CommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, showDevicesDialog, false);
                scanner           = scannerDevice == null || scannerDevice.Items.Count < 1
                            ? null
                            : new Scanner(scannerDevice.Items[1]);

/*
 *              Debug.WriteLine("-------Output all properties----------------");
 *              if(scanner != null)
 *              {
 *                for (int i = 1; i < scannerDevice.Items[1].Properties.Count; i++)
 *                {
 *                      var property = scannerDevice.Items[1].Properties[i];
 *                      Debug.WriteLine("{0}:{1}", property.Name,property.get_Value());
 *                }
 *              }
 */
            });
            return(scanner);
        }
Esempio n. 3
0
    public static string SelectDevice()
    {
        ICommonDialog dialog = new CommonDialog();
        Device        device = dialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

        return((device == null)? string.Empty: device.DeviceID);
    }
Esempio n. 4
0
 public Scanner()
 {
     try
     {
         dlg     = new CommonDialog();
         oDevice = dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
     }
     catch (Exception)
     {
         System.Windows.Forms.MessageBox.Show("NO SE HA DETECTADO NINGUN ESCANER, INTENTELO MAS TARDE", "SYSBA", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
         this.mensaje = 1;
     }
 }
Esempio n. 5
0
        public ImageFile Scan(ProgressDialogController ctrl, bool colorSetting = true)
        {
            try
            {
                var image  = new ImageFile();
                var dialog = new CommonDialog();

                ctrl.SetTitle("STARTING SCANNER");
                ctrl.SetMessage("This can take a few seconds...");

                var x    = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);
                var item = x.Items[1];
                // HorizontalResolution
                item.Properties["6147"].set_Value(75);
                // VerticalResolution
                item.Properties["6148"].set_Value(75);

                // CurrentInten, 1 - Color, 4 - Black & White
                if (colorSetting)
                {
                    item.Properties["6146"].set_Value(1);
                }
                else
                {
                    item.Properties["6146"].set_Value(4);
                }


                image = dialog.ShowTransfer(item, "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}", true);

                if (image != null)
                {
                    ctrl.SetTitle("SCANNING FINISHED!");
                    ctrl.SetMessage($"File Scanned Successfully...");
                }
                return(image);
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == -2145320939)
                {
                    throw new ScannerNotFoundException();
                }
                else
                {
                    throw new ScannerException(ex.Message, ex);
                }
            }
        }
Esempio n. 6
0
        public WiaScanner ShowSelectDevice()
        {
            ICommonDialog dialog = new CommonDialog();
            Device        device = dialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (device != null)
            {
                return new WiaScanner {
                           Id = device.DeviceID, Name = device.Properties["Name"].get_Value().ToString()
                }
            }
            ;
            else
            {
                return(null);
            }
        }
Esempio n. 7
0
        public static Image Scan()
        {
            try
            {
                CommonDialog commonDialog  = new CommonDialog();
                Device       scannerDevice = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType);

                if (scannerDevice != null)
                {
                    Item scannerItem = scannerDevice.Items[1];
                    SetDefaultScannerProperties(scannerItem);
                    ImageFile scanResult = scannerItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}");

                    if (scanResult != null)
                    {
                        Image img;
                        lock (scanResult)
                        {
                            ImageFile    image  = (ImageFile)scanResult;
                            MemoryStream stream = new MemoryStream((byte[])image.FileData.get_BinaryData());
                            img = Image.FromStream(stream);
                        }

                        return(img);
                    }
                    else
                    {
                        MessageBox.Show("Skanowanie nie powiodło się, spróbuj ponownie");
                    }
                }
                else
                {
                    MessageBox.Show("Nie znaleziono skanera, sprawdź połączenie i spróbuj ponownie.");
                }
                return(null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Skanowanie nie powiodło się, spróbuj ponownie");
                return(null);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Use scanner to scan an image (with user selecting the scanner from a dialog).
        /// </summary>
        /// <returns>Scanned images.</returns>
        public static List<Image> Scan(ScanSettings settings)
        {
            ICommonDialog dialog = new CommonDialog();
            Device device = null;
            try
            {
                device = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            }
            catch (Exception)
            {
                throw new Exception("Cannot initialize scanner selection window. No WIA scanner installed?");
            }

            if (device != null)
            {
                return Acquire(device, settings);
            }
            else
            {
                throw new Exception("You must first select a WIA scanner.");
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Use scanner to scan an image (with user selecting the scanner from a dialog).
        /// </summary>
        /// <returns>Scanned images.</returns>
        public static List <Image> Scan(ScanSettings settings)
        {
            ICommonDialog dialog = new CommonDialog();
            Device        device = null;

            try
            {
                device = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            }
            catch (Exception)
            {
                throw new Exception("Cannot initialize scanner selection window. No WIA scanner installed?");
            }

            if (device != null)
            {
                return(Acquire(device, settings));
            }
            else
            {
                throw new Exception("You must first select a WIA scanner.");
            }
        }
Esempio n. 10
0
        private bool SelectDevice()
        {
            try
            {
                CommonDialog commonDialog = new CommonDialog();
                Device       device       = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, true);
                _deviceId = device.DeviceID;
            }
            catch (Exception ex)
            {
                UserSettings.Settings.LogException(LogSeverity.Warning, "Failed to select scanner", ex);

                CatfoodMessageBox.Show(MainWindow.MessageBoxIcon,
                                       this,
                                       WiaErrorOrMessage(ex),
                                       "Failed to select scanner - Catfood PdfScan",
                                       CatfoodMessageBoxType.Ok,
                                       CatfoodMessageBoxIcon.Error,
                                       ex);
            }

            return(!string.IsNullOrEmpty(_deviceId));
        }
Esempio n. 11
0
        /// <summary>
        /// Use scanner to scan an image (with user selecting the scanner from a dialog).
        /// </summary>
        /// <returns>Scanned images.</returns>
        public static List <Bitmap> Scan(ScanSettings settings)
        {
            ICommonDialog dialog = new CommonDialog();
            Device        device = null;

            try
            {
                device = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false);
            }
            catch (Exception)
            {
                throw new Exception("Không thể khởi tạo máy scan. Vui lòng kiểm tra lại!");
            }

            if (device != null)
            {
                return(Acquire(device, settings));
            }
            else
            {
                throw new Exception("Vui lòng chọn máy quét.");
            }
        }
Esempio n. 12
0
        void Scan(ScanColor clr, int dpi)
        {
            string deviceid;
            //Choose Scanner
            CommonDialog class1 = new CommonDialog();
            Device       d      = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);

            if (d != null)
            {
                deviceid = d.DeviceID;
            }
            else
            {
                //no scanner chosen
                return;
            }
            WIA.CommonDialog WiaCommonDialog = new CommonDialog();
            bool             hasMorePages    = true;
            int x        = 0;
            int numPages = 0;

            while (hasMorePages)
            {
                //Create DeviceManager
                DeviceManager manager = new DeviceManager();
                Device        WiaDev  = null;
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == deviceid)
                    {
                        WIA.Properties infoprop = null;
                        infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break;
                    }
                }
                //Start Scan
                WIA.ImageFile img  = null;
                WIA.Item      Item = WiaDev.Items[1] as WIA.Item;
                //set properties //BIG SNAG!! if you call WiaDev.Items[1] apprently it erases the item from memory so you cant call it again
                Item.Properties["6146"].set_Value((int)clr);//Item MUST be stored in a variable THEN the properties must be set.
                Item.Properties["6147"].set_Value(dpi);
                Item.Properties["6148"].set_Value(dpi);
                try
                {//WATCH OUT THE FORMAT HERE DOES NOT MAKE A DIFFERENCE... .net will load it as a BITMAP!
                    var testFormat = FormatID.wiaFormatJPEG;
                    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, testFormat, false);
                    //process image:
                    //Save to file and open as .net IMAGE
                    string varImageFileName = Path.GetTempFileName();
                    if (File.Exists(varImageFileName))
                    {
                        //file exists, delete it
                        File.Delete(varImageFileName);
                    }
                    img.SaveFile(varImageFileName);
                    Image ret = Image.FromFile(varImageFileName);
                    EventHandler <WiaImageEventArgs> temp = Scanning;
                    if (temp != null)
                    {
                        temp(this, new WiaImageEventArgs(ret));
                    }
                    numPages++;
                    img = null;
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    Item = null;
                    //determine if there are any more pages waiting
                    Property documentHandlingSelect = null;
                    Property documentHandlingStatus = null;

                    foreach (Property prop in WiaDev.Properties)
                    {
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
                        {
                            documentHandlingSelect = prop;
                        }
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
                        {
                            documentHandlingStatus = prop;
                        }
                    }
                    hasMorePages = false; //assume there are no more pages
                    if (documentHandlingSelect != null)
                    //may not exist on flatbed scanner but required for feeder
                    {
                        //check for document feeder
                        if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                        {
                            hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                        }
                    }
                    x++;
                }
            }
            EventHandler tempCom = ScanComplete;

            if (tempCom != null)
            {
                tempCom(this, EventArgs.Empty);
            }
        }
        public ImageFile Acquire()
        {
            ImageFile image;

            try
            {
                CommonDialog dialog = new CommonDialog();

                var type = WiaDeviceType.ScannerDeviceType;
                if (_deviceKind == DeviceKind.Camera)
                {
                    type = WiaDeviceType.CameraDeviceType;
                }

                var device = dialog.ShowSelectDevice(type, false, false);

                foreach (var item in device.Items)
                {
                }
                foreach (Property propertyItem in device.Properties)
                {
                    //if (!propertyItem.IsReadOnly)
                    {
                        Debug.WriteLine(String.Format("{0}\t{1}\t{2}", propertyItem.Name, propertyItem.PropertyID, propertyItem.get_Value()));
                    }
                }

                //this gives the UI we want (can select profiles), but there's no way for an application to get the
                //results of the scan!!!! It just asks the user where to save the image. GRRRRRRR.
                //object x = dialog.ShowAcquisitionWizard(device);


                //With the low-end canoscan I'm using, it just ignores these settings, so we just get a bitmap of whatever
                //b&w / color the user requested

                image = dialog.ShowAcquireImage(
                    type,
                    WiaImageIntent.GrayscaleIntent,
                    WiaImageBias.MaximizeQuality,
                    WIA.FormatID.wiaFormatBMP,                             //We'll automatically choose the format later depending on what we see
                    false,
                    true,
                    false);
                UsageReporter.SendNavigationNotice("AcquiredImage/" + (_deviceKind == DeviceKind.Camera?"Camera": "Scanner"));

                return(image);
            }
            catch (COMException ex)
            {
                if (ex.ErrorCode == -2145320939)
                {
                    throw new ImageDeviceNotFoundException();
                }
                else
                {
                    //NB: I spend some hours working on adding this wiaaut.dll via the installer, using wix heat, but it was one problem after another.
                    //Decided eventually that it wasn't worth it at this point; it's easy enough to install by hand.
                    if (ErrorReport.GetOperatingSystemLabel().Contains("XP"))
                    {
                        var comErrorCode = new Win32Exception(((COMException)ex).ErrorCode).ErrorCode;

                        if (comErrorCode == 80040154)
                        {
                            throw new WIA_Version2_MissingException();
                        }
                    }

                    throw new ImageDeviceException("COM Exception", ex);
                }
            }
        }
Esempio n. 14
0
 /// <summary>
 /// The select scaner.
 /// </summary>
 public void SelectScaner(Device device = null)
 {
     _wiaDiag = _wiaDiag ?? new CommonDialog();
     _wiaDev  = device ?? _wiaDiag.ShowSelectDevice(WiaDeviceType.CameraDeviceType, false, false);
     _scaner  = _wiaDev.Items[1];
 }
Esempio n. 15
0
 public static Device FromUserDialog(
     WiaDeviceType deviceType = WiaDeviceType.UnspecifiedDeviceType, bool alwaysSelectDevice = false)
 {
     CommonDialog wiaDialog = new CommonDialog();
     return wiaDialog.ShowSelectDevice(deviceType, alwaysSelectDevice, false);
 }
Esempio n. 16
0
        void Scan(ScanColor clr, int dpi, string deviceuuid, string iniPath)
        {
            string deviceid;

            //Choose Scanner
            if (String.IsNullOrEmpty(deviceuuid))
            {
                CommonDialog class1 = new CommonDialog();
                Device       d      = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
                if (d == null)
                {
                    return; //no scanner chosen
                }
                deviceid = d.DeviceID;
                if (File.Exists(iniPath))
                {
                    //Connect to Ini File "Config.ini" in current directory
                    IniInterface oIni = new IniInterface(iniPath);
                    oIni.WriteValue("Scan", "deviceuuid", deviceid);
                    CertificateScanner.ExceptionDecor.ExceptionDecorator.Info(String.Format("New scanner with uuid=\"{0}\" added", deviceid));
                }
            }
            else
            {
                deviceid = deviceuuid;
            }
            CommonDialog WiaCommonDialog = new CommonDialog();
            bool         hasMorePages    = true;
            int          x        = 0;
            int          numPages = 0;

            while (hasMorePages)
            {
                //Create DeviceManager
                DeviceManager manager = new DeviceManager();
                Device        WiaDev  = null;
                foreach (DeviceInfo info in manager.DeviceInfos)
                {
                    if (info.DeviceID == deviceid)
                    {
                        Properties infoprop = info.Properties;
                        //connect to scanner
                        WiaDev = info.Connect();
                        break;
                    }
                }
                //Start Scan
                ImageFile img  = null;
                Item      Item = WiaDev.Items[1] as Item;
                //set properties //BIG SNAG!! if you call WiaDev.Items[1] apprently it erases the item from memory so you cant call it again
                Item.Properties["6146"].set_Value((int)clr);//Item MUST be stored in a variable THEN the properties must be set.
                Item.Properties["6147"].set_Value(dpi);
                Item.Properties["6148"].set_Value(dpi);
                try
                {//WATCH OUT THE FORMAT HERE DOES NOT MAKE A DIFFERENCE... .net will load it as a BITMAP!
                    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}" /*WIA.FormatID.wiaFormatJPEG*/, false);
                    //process image:
                    //Save to file and open as .net IMAGE
                    string varImageFileName = Path.GetTempFileName();
                    if (File.Exists(varImageFileName))
                    {
                        //file exists, delete it
                        File.Delete(varImageFileName);
                    }
                    img.SaveFile(varImageFileName);
                    Image ret;
                    using (var fs = new FileStream(varImageFileName, FileMode.Open)) //File not block
                    {
                        var bmp = new Bitmap(fs);
                        ret = (Bitmap)bmp.Clone();
                        EventHandler <WiaImageEventArgs> temp = Scanning;
                        if (temp != null)
                        {
                            temp(this, new WiaImageEventArgs(ret));
                        }
                    }
                    numPages++;
                    img = null;
                    File.Delete(varImageFileName);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    Item = null;
                    //determine if there are any more pages waiting
                    Property documentHandlingSelect = null;
                    Property documentHandlingStatus = null;

                    foreach (Property prop in WiaDev.Properties)
                    {
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
                        {
                            documentHandlingSelect = prop;
                        }
                        if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
                        {
                            documentHandlingStatus = prop;
                        }
                    }
                    hasMorePages = false; //assume there are no more pages
                    if (documentHandlingSelect != null)
                    //may not exist on flatbed scanner but required for feeder
                    {
                        //check for document feeder
                        if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
                        {
                            hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
                        }
                    }
                    x++;
                }
            }
            EventHandler tempCom = ScanComplete;

            if (tempCom != null)
            {
                tempCom(this, EventArgs.Empty);
            }
        }
Esempio n. 17
0
 public Scanner()
 {
     commonDialog  = new CommonDialog();
     scannerDevice = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);
 }
        public Task <bool> Scann(PdfViewer obj = null)
        {
            scannedDoc = new List <string>();
            PDFViewer  = obj;
            Application.Current.Dispatcher.Invoke((System.Action)(delegate
            {
                obj.Visibility = Visibility.Collapsed;
            }));

            StaticSourcesViewModel.ShowMensajeProgreso("Espere Por Favor, Escaneando...");
            try
            {
                var morePages         = true;
                var commonDialogClass = new CommonDialog();
                var scannerDevice     = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false);
                var pagecount         = 0;

                if (scannerDevice != null)
                {
                    scannerDevice.Properties["Pages"].set_Value(1);
                    scannerDevice.Properties["Document Handling Select"].set_Value(1);

                    var document = new PdfDocument();
                    while (morePages)
                    {
                        try
                        {
                            var scannnerItem = scannerDevice.Items[1];
                            AdjustScannerSettings(scannnerItem, 150, 0, 0, 1250, 1700, 0, 0, WiaImageIntent.ColorIntent);

                            var img = (ImageFile)scannnerItem.Transfer("{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}");
                            if (img != null)
                            {
                                document.Pages.Add(new PdfPage());
                                var xgr  = XGraphics.FromPdfPage(document.Pages[pagecount]);
                                var Ximg = XImage.FromBitmapSource(ConvertScannedImage(img));

                                xgr.DrawImage(Ximg, 0, 0, 595, 842);

                                pagecount++;
                            }

                            WIA.Property documentHandlingSelect = null;
                            WIA.Property documentHandlingStatus = null;

                            foreach (WIA.Property prop in scannerDevice.Properties)
                            {
                                if (prop.PropertyID == 3088)
                                {
                                    documentHandlingSelect = prop;
                                }

                                if (prop.PropertyID == 3087)
                                {
                                    documentHandlingStatus = prop;
                                }
                            }

                            morePages = false;

                            if (documentHandlingSelect != null)
                            {
                                if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & 0x00000001) != 0)
                                {
                                    morePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & 0x00000001) != 0);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            if (pagecount <= 0)
                            {
                                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                                {
                                    if (ex.Message == "Exception from HRESULT: 0x80210003")
                                    {
                                        StaticSourcesViewModel.Mensaje("Digitalización", "Revise que la bandeja tenga hojas", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION);
                                    }
                                    else
                                    if (ex.Message == "Value does not fall within the expected range.")
                                    {
                                        StaticSourcesViewModel.Mensaje("Digitalización", "*- Revise que el escáner este encendido.\n*- Revise que el escáner este bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION);
                                    }
                                    else
                                    {
                                        StaticSourcesViewModel.Mensaje("Digitalización", "Hay problemas para conectarse con el escaner", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION);
                                    }
                                }));
                            }

                            morePages = false;
                        }
                    }

                    if (pagecount > 0)
                    {
                        fileNamepdf = Path.GetTempPath() + Path.GetRandomFileName().Split('.')[0] + ".pdf";

                        document.Save(fileNamepdf);

                        ScannedDocument = File.ReadAllBytes(fileNamepdf);

                        Application.Current.Dispatcher.Invoke((System.Action)(delegate
                        {
                            obj.LoadFile(fileNamepdf);
                            obj.Visibility = Visibility.Visible;
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                Application.Current.Dispatcher.Invoke((System.Action)(delegate
                {
                    if (ex.Message.Contains("HRESULT: 0x80210015"))
                    {
                        StaticSourcesViewModel.Mensaje("Digitalización", "*- No tienes ningun escaner instalado.\n*- Revise que el escáner este encendido.\n*- Revise que el escáner este bien conectado", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION);
                    }
                    if (ex.Message.Contains("HRESULT: 0x80070021"))
                    {
                        StaticSourcesViewModel.Mensaje("Digitalización", "Hay problemas para conectarse con el escaner", StaticSourcesViewModel.enumTipoMensaje.MENSAJE_INFORMACION);
                    }
                }));
            }
            StaticSourcesViewModel.CloseMensajeProgreso();
            return(TaskEx.FromResult(true));
        }
Esempio n. 19
0
 public Scanner()
 {
     commonDialog = new CommonDialog();
     scannerDevice = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false);
 }
Esempio n. 20
0
 public void SelectDevice()
 {
     try
     {
         _dialog = new CommonDialog();
         _device = _dialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false);
     }
     catch (COMException ex)
     {
         if (ex.ErrorCode == -2145320939)
         {
             throw new WiaOperationException("No Webcam Device Exist", ex);
         }
     }
 }
		public ImageFile Acquire()
		{
			ImageFile image;

			try
			{
				CommonDialog dialog = new CommonDialog();

				var type = WiaDeviceType.ScannerDeviceType;
				if(_deviceKind==DeviceKind.Camera)
						type = WiaDeviceType.CameraDeviceType;

				var device = dialog.ShowSelectDevice(type, false, false);

				foreach (var item in device.Items)
				{

				}
				foreach (Property propertyItem in device.Properties)
				{
					//if (!propertyItem.IsReadOnly)
					{
						Debug.WriteLine(String.Format("{0}\t{1}\t{2}", propertyItem.Name, propertyItem.PropertyID, propertyItem.get_Value()));
					}
				}

				//this gives the UI we want (can select profiles), but there's no way for an application to get the
				//results of the scan!!!! It just asks the user where to save the image. GRRRRRRR.
				//object x = dialog.ShowAcquisitionWizard(device);


				//With the low-end canoscan I'm using, it just ignores these settings, so we just get a bitmap of whatever
				//b&w / color the user requested

				  image = dialog.ShowAcquireImage(
						type,
						WiaImageIntent.GrayscaleIntent,
						WiaImageBias.MaximizeQuality,
						WIA.FormatID.wiaFormatBMP, //We'll automatically choose the format later depending on what we see
					   false,
					   true,
						false);
				UsageReporter.SendNavigationNotice("AcquiredImage/" + (_deviceKind == DeviceKind.Camera?"Camera": "Scanner"));

				return image;
			}
			catch (COMException ex)
			{
				if (ex.ErrorCode == -2145320939)
				{
					throw new ImageDeviceNotFoundException();
				}
				else
				{
					//NB: I spend some hours working on adding this wiaaut.dll via the installer, using wix heat, but it was one problem after another.
					//Decided eventually that it wasn't worth it at this point; it's easy enough to install by hand.
					if (ErrorReport.GetOperatingSystemLabel().Contains("XP"))
					{
						var comErrorCode = new Win32Exception(((COMException) ex).ErrorCode).ErrorCode;

						if (comErrorCode == 80040154)
						{
							throw new WIA_Version2_MissingException();
						}
					}

					throw new ImageDeviceException("COM Exception", ex);
				}
			}
		}