public ImageFile Scan() { ImageFile image; try { CommonDialog dialog = new CommonDialog(); image = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MaximizeQuality, WIA.FormatID.wiaFormatJPEG, false, true, false); return image; } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { throw new ScannerNotFoundException(); } else { throw new ScannerException("COM Exception", ex); } } }
public ImageFile Scan() { ImageFile image; try { CommonDialog dialog = new CommonDialog(); image = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MaximizeQuality, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", //FormatID.wiaFormatJPEG false, true, false); return(image); } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { throw new ScannerNotFoundException(); } else { throw new ScannerException("COM Exception", ex); } } }
public ImageFile Scan() { ImageFile image; try { CommonDialog dialog = new CommonDialog(); image = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MinimizeSize, FormatID.wiaFormatJPEG, false, true, false); return(image); } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { throw new ScannerNotFoundException(); } else { throw new ScannerException("COM Exception", ex); } } }
public ImageFile Scann() { try { CommonDialog dialog = new CommonDialog(); ImageFile image = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MaximizeQuality, FormatID.wiaFormatJPEG, false, false, false); return(image); } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { throw new Exception("Scanner not found"); //throw new ScannerNotFoundException(); } else { throw new Exception("COM Exception", ex); } } //dlg.ShowAcquisitionWizard(oDevice); }
// string DeviceID; public List <System.Drawing.Image> Scan() { var deviceManager = new DeviceManager(); List <System.Drawing.Image> listImages = new List <System.Drawing.Image>(); _existScanner = false; _existScanner = deviceManager.DeviceInfos.Count > 0; if (_existScanner) { //WIAScanner.Scan(); bool hasMorePages = true; //Device Scanners; WIA.CommonDialog Common; Common = new CommonDialog(); // Scanners = Common.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); int i = 0; while (hasMorePages) { try { //Item item = Scanners.GetItem(); ImageFile Image = Common.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MaximizeQuality, wiaFormatJPEG, false, true, false); if (Image != null) { Byte[] imageBytes = (byte[])Image.FileData.get_BinaryData(); MemoryStream ms = new MemoryStream(imageBytes); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); listImages.Add(img); } else { hasMorePages = false; } } catch (Exception ex) { _existScanner = false; hasMorePages = false; } finally { i++; } } } return(listImages); }
/// <summary> /// Performs image scanning, saving it to user specified location and loading it to the preview items /// </summary> private void OnScanImage() { ImageFile image; try { CommonDialog dialog = new CommonDialog(); image = dialog.ShowAcquireImage( WiaDeviceType.ScannerDeviceType, WiaImageIntent.GrayscaleIntent, WiaImageBias.MaximizeQuality, WIA.FormatID.wiaFormatPNG, false, true, false); if (image == null) { return; } string savePath = DialogManager.ShowSaveScannedImageDialog(string.Empty); image.SaveFile(savePath); this.LoadPreviewImage(savePath); } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { DialogManager.ShowErrorDialog( "Error retrieving a list of scanners. Please make sure your device is connected and turned on."); } else { DialogManager.ShowErrorDialog("COM Exception : " + ex.Message); } } catch (Exception e) { DialogManager.ShowErrorDialog("Error occurred : " + e.Message); } }
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); } }
public static List <string> Scan(string deviceId) { ICommonDialog wiaCommonDialog = new CommonDialog(); List <string> fileNames = new List <string>(); bool hasSheetFeeder = false; bool hasMorePages = false; do { Device device = SelectDevice(deviceId); ImageFile image = null; try { image = (ImageFile)wiaCommonDialog.ShowAcquireImage(); if (image != null) { string fileName = System.IO.Path.GetTempFileName(); System.IO.File.Delete(fileName); image.SaveFile(fileName); fileNames.Add(fileName); } } finally { image = null; foreach (Property prop in device.Properties) { if (prop.PropertyID == (uint)WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT) { hasSheetFeeder = ((WIA_DPS_DOCUMENT_HANDLING_SELECT)prop.get_Value() == WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER); } if (prop.PropertyID == (uint)WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS) { hasMorePages = ((WIA_DPS_DOCUMENT_HANDLING_STATUS)prop.get_Value() == WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY); } } } } while (hasSheetFeeder && hasMorePages); return(fileNames); }
public static bool Scan(string path) { string tempPath = Path.GetTempFileName(); if (File.Exists(tempPath)) { File.Delete(tempPath); } ImageFormat format = ImageFormat.Jpeg; var dlg = new CommonDialog(); ImageFile image = dlg.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.ColorIntent, WiaImageBias.MinimizeSize, format.Guid.ToString("B"), false, false, false); if (image == null) { return(false); } image.SaveFile(tempPath); // Get a bitmap. var bmp1 = new Bitmap(tempPath); ImageCodecInfo jgpEncoder = GetEncoder(ImageFormat.Jpeg); // Create an Encoder object based on the GUID // for the Quality parameter category. Encoder myEncoder = Encoder.Quality; // Create an EncoderParameters object. // An EncoderParameters object has an array of EncoderParameter // objects. In this case, there is only one // EncoderParameter object in the array. EncoderParameters myEncoderParameters = new EncoderParameters(1); EncoderParameter myEncoderParameter = new EncoderParameter(myEncoder, 80L); myEncoderParameters.Param[0] = myEncoderParameter; bmp1.Save(path, jgpEncoder, myEncoderParameters); return(true); }
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); } } }
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); } } }