public override bool SelectDevice() { CommonDialogClass wiaCommonDialog = new CommonDialogClass(); Device device = null; try { device = wiaCommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, true); if (device != null) { m_DeviceID = device.DeviceID; FillDeviceData(device); return(true); } else { return(false); } } catch (COMException ex) { if ((WiaScannerError)ex.ErrorCode == WiaScannerError.ScannerNotAvailable) { return(false); } else { WiaScannerException se = BuildScannerException(device, ex); throw se; } } }
/// <summary> /// Gets the device that will be used to acquire an image. /// </summary> private static WiaResult GetDevice(out Device device) { device = null; try { CommonDialogClass cdc = new CommonDialogClass(); device = cdc.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, false, false); if (device == null) //Either the user cancelled OR we have no device we can use to get an image. { return(new WiaResult(string.Format(ERROR_MESSAGE_FORMAT, "get the capture device", "No device was selected"))); } else { return(WiaResult.Success); } } catch (COMException ce) { if (logger.IsDebugEnabled) { logger.Debug(WiaConstants.LoggingConstants.ExceptionOccurred, ce); } return(new WiaResult(string.Format(ERROR_MESSAGE_FORMAT, "get the capture device", WiaError.GetErrorMessage(ce)))); } }
public ActionResult Scan(string PatientRegNo, string Email) { string path = ""; CommonDialogClass commonDialogClass = new CommonDialogClass(); //CommonDialogClass commonDialogClass = new CommonDialogClass(); try { string date = AutoGanrateferecnCode(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, 200, 0, 0, 1700, 2300, 0, 0); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, false); if (scanResult != null) { ImageFile image = (ImageFile)scanResult; string fileName = Server.MapPath("~/") + "MRDFiles/" + date + ".JPEG"; SaveImageToPNGFile(image, fileName); path = "/MRDFiles/" + date + ".JPEG"; } } } catch (Exception ex) { throw; } return(new JsonResult { Data = path, JsonRequestBehavior = JsonRequestBehavior.AllowGet }); }
private void btnScanNow_Click(object sender, EventArgs e) { try { CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, (int)nudRes.Value, 0, 0, (int)nudWidth.Value, (int)nudHeight.Value, 0, 0, cmbCMIndex); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatTIFF, false); //picScan.Image = (System.Drawing.Image)scanResult; if (scanResult != null) { ImageFile image = (ImageFile)scanResult; try { System.IO.File.Delete("test.tiff"); } catch (Exception) { } SaveImageToTiff(image, "test.tiff"); pbScan.Image = (Image)Image.FromFile("test.tiff").Clone(); } } } catch (Exception err) { MessageBox.Show("Please check your device connection, device not found." + Environment.NewLine + "Error message:" + err.Message, "Device Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static ScanDevice PromptForDevice() { var wiaCommonDialog = new CommonDialogClass(); try { Device d = wiaCommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); if (d == null) { return(null); } return(new ScanDevice(d.DeviceID, GetDeviceName(d.DeviceID))); } catch (COMException e) { if ((uint)e.ErrorCode == Errors.NO_DEVICE_FOUND) { throw new NoDevicesFoundException(); } if ((uint)e.ErrorCode == Errors.OFFLINE) { throw new DeviceOfflineException(); } throw new ScanDriverUnknownException(e); } }
public void Configuration()//процедура ручной настройки сканера { try { var commonDialog = new CommonDialogClass(); _scanDevice = commonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true); if (_scanDevice == null) { return; } var items = commonDialog.ShowSelectItems(_scanDevice); if (items.Count < 1) { return; } _scannerItem = items[1]; SaveProp(_scanDevice.Properties, ref _defaultDeviceProp); SaveConfig();// сохраняем конфигурацию } catch (Exception e) { MessageBox.Show(e.Message, "Интерфейс сканера не доступен"); } }
/// <summary> /// Use scanner to scan an image (with user selecting the scanner from a dialog). /// </summary> /// <returns>Scanned images.</returns> public static string Scan() { ICommonDialog dialog = new CommonDialogClass(); var device = dialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (device != null) { return(Scan(device.DeviceID)); } else { throw new COMException("You must select a device for scanning."); } }
public ADFScan() { CommonDialogClass class1 = new CommonDialogClass(); Device d = class1.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); if (d != null) { _deviceID = d.DeviceID; } else { //no scanner chosen return; } }
public static ScanDevice PromptForScanDevice() { var wiaCommonDialog = new CommonDialogClass(); try { Device d = wiaCommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); if (d == null) { return null; } return new ScanDevice(d.DeviceID, GetDeviceName(d.DeviceID)); } catch (COMException e) { ThrowDeviceError(e); return null; } }
private void button1_Click(object sender, EventArgs e) { dlg = new CommonDialogClass(); oDevice = dlg.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); try { Scann(); button1.Text = "Image scanned"; OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { pictureBox1.Image = Image.FromFile(dlg.FileName); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ButtonLoadCameraClick(object sender, EventArgs e) { var deviceManager = new DeviceManagerClass(); if (deviceManager.DeviceInfos.Cast<DeviceInfo>().All(p => p.Type != WiaDeviceType.CameraDeviceType)) { MessageBox.Show(CanNotFindAnyDevice); return; } var commonDialog = new CommonDialogClass(); var device = commonDialog.ShowSelectDevice(WiaDeviceType.CameraDeviceType, true); if (device == null) { return; } this.Import(new CameraPhotoProvider(device)); }
private void ButtonDeviceClick(object sender, System.EventArgs e) { DeviceManager deviceManager = new DeviceManagerClass(); if (deviceManager.DeviceInfos.Cast<DeviceInfo>().All(p => p.Type != WiaDeviceType.CameraDeviceType)) { MessageBox.Show(CanNotFindAnyDevice); return; } var commonDialog = new CommonDialogClass(); var device = commonDialog.ShowSelectDevice(WiaDeviceType.CameraDeviceType, true); if (device == null) { return; } this.settings.DeviceId = device.DeviceID; this.UpdateControls(); }
private void ScanDoc() { try { CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, (int)nudRes.Value, 0, 0, (int)nudWidth.Value, (int)nudHeight.Value, 0, 0, cmbCMIndex); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, false); //picScan.Image = (System.Drawing.Image)scanResult; if (scanResult != null) { ImageFile image = (ImageFile)scanResult; string fileName = ""; string foldername = Path.GetFullPath(@"\image\") + DateTime.Now.ToString("yyyyMMdd"); string txtPath = Path.GetFullPath(foldername); var files = Directory.GetFiles(txtPath, "*.PNG"); try { string f = ((files.Max(p1 => Int32.Parse(Path.GetFileNameWithoutExtension(p1)))) + 1).ToString(); fileName = txtPath + "\\" + f + ".PNG"; } catch (Exception ex) { fileName = txtPath + "\\" + "1.PNG"; } SaveImageToPNG(image, fileName); picScan.ImageLocation = fileName; } } } catch (Exception err) { MessageBox.Show("Check the Device Connection \n or \n Change the Scanner Device", "Devic Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void ScanDoc() { try { CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, 150, 0, 0, 1250, 1700, 0, 0, 0); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatTIFF, false); //picScan.Image = (System.Drawing.Image)scanResult; if (scanResult != null) { ImageFile image = (ImageFile)scanResult; string fileName = ""; var files = Directory.GetFiles(clsGlobalVariables.ScannerFilesDirectory, "*.tiff"); try { string f = ((files.Max(p1 => Int32.Parse(Path.GetFileNameWithoutExtension(p1)))) + 1).ToString(); fileName = clsGlobalVariables.ScannerFilesDirectory + "\\" + f + ".tiff"; } catch (Exception ex) { clsGlobalFunctions.ErrorLog(ex); //Log Error fileName = clsGlobalVariables.ScannerFilesDirectory + "\\" + "1.tiff"; } SaveImageToTiff(image, fileName); picScan.ImageLocation = fileName; } } } catch (Exception ex) { clsGlobalFunctions.ErrorLog(ex); //Log Error MessageBox.Show("Check the Device Connection \n or \n Change the Scanner Device", "Devic Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static string SelectDeviceUI() { CommonDialogClass WIACommonDialog = new CommonDialogClass(); Device d; try { d = WIACommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); } catch(System.Runtime.InteropServices.COMException e) { if ((uint)e.ErrorCode == NO_DEVICE_FOUND) { throw new Exceptions.ENoScannerFound(); } else { throw e; } } return d.DeviceID; }
public static string SelectDeviceUI() { CommonDialogClass WIACommonDialog = new CommonDialogClass(); Device d; try { d = WIACommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); } catch (System.Runtime.InteropServices.COMException e) { if ((uint)e.ErrorCode == NO_DEVICE_FOUND) { throw new Exceptions.ENoScannerFound(); } else { throw e; } } return(d.DeviceID); }
private void ScanDoc() { CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; SelectDeviceDocumentHandling(scannerDevice, DeviceDocumentHandling.Feeder); AdjustScannerSettings(scannnerItem, (int)nudRes.Value, 0, 0, (int)nudWidth.Value, (int)nudHeight.Value, 30, -50, cmbColorMode.SelectedIndex); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatTIFF, false); //picScan.Image = (System.Drawing.Image)scanResult; if (scanResult != null) { ImageFile image = (ImageFile)scanResult; string fileName = ""; var files = Directory.GetFiles(txtPath.Text + "\\temp\\", "*.jpg"); try { string f = ((files.Max(p1 => Int32.Parse(Path.GetFileNameWithoutExtension(p1)))) + 1).ToString(); fileName = txtPath.Text + "\\temp\\" + f + ".jpg"; } catch { fileName = txtPath.Text + "\\temp\\" + "1.jpg"; } SaveImageToTiff(image, fileName); picScan.ImageLocation = fileName; } } }
private void Btn_scan_Click(object sender, RoutedEventArgs e) { try { if (sender != null) { SectionData.StartAwait(grid_main); } CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { WIA.Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, 600, 0, 0, 1010, 620, 0, 0); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatPNG, false); if (scanResult != null) { ImageFile image = (ImageFile)scanResult; var imageBytes = (byte[])image.FileData.get_BinaryData();// <-- Converts the ImageFile to a byte array var bitmapImage = new BitmapImage(); if (imageBytes != null) { using (var memoryStream = new MemoryStream(imageBytes)) { bitmapImage.BeginInit(); bitmapImage.CacheOption = BitmapCacheOption.OnLoad; bitmapImage.StreamSource = memoryStream; bitmapImage.EndInit(); } img_upload.Background = new ImageBrush(bitmapImage); } // configure trmporery path //string dir = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; string dir = Directory.GetCurrentDirectory(); string tmpPath = System.IO.Path.Combine(dir, Global.ScannedImageLocation); if (System.IO.File.Exists(tmpPath)) { System.IO.File.Delete(tmpPath); } SaveImageToJpgFile(image, tmpPath); openFileDialog.FileName = tmpPath; } } if (sender != null) { SectionData.EndAwait(grid_main); } } catch (System.Runtime.InteropServices.COMException) { if (sender != null) { SectionData.EndAwait(grid_main); } System.Windows.MessageBox.Show("Problem with scanning device. Please ensure that the scanner is properly connected and switched on", "Inweon Grain Management System"); } }
public static ScanDevice PromptForDevice() { var wiaCommonDialog = new CommonDialogClass(); try { Device d = wiaCommonDialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, true, false); if (d == null) { return null; } return new ScanDevice(d.DeviceID, GetDeviceName(d.DeviceID)); } catch (COMException e) { if ((uint)e.ErrorCode == Errors.NO_DEVICE_FOUND) { throw new NoDevicesFoundException(); } if ((uint)e.ErrorCode == Errors.OFFLINE) { throw new DeviceOfflineException(); } throw new ScanDriverUnknownException(e); } }
private void Scan(ScanColor clr, int dpi) { // Microsoft.Win32.RegistryKey jpegKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"CLSID\{D2923B86-15F1-46FF-A19A-DE825F919576}\SupportedExtension\.jpg"); //string jpegGuid = jpegKey.GetValue("FormatGUID") as string; CommonDialogClass commonDialogClass = new CommonDialogClass(); Device device = commonDialogClass.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (device != null) { string deviceID = device.DeviceID; WIA.CommonDialog commonDialog = new CommonDialogClass(); bool flag = true; int num = 0; int num2 = 0; while (flag) { DeviceManager deviceManager = new DeviceManagerClass(); Device device2 = null; foreach (DeviceInfo deviceInfo in deviceManager.DeviceInfos) { if (deviceInfo.DeviceID == deviceID) { WIA.Properties properties = deviceInfo.Properties; device2 = deviceInfo.Connect(); break; } } Item item = device2.Items[1]; object obj = (int)clr; object obj2 = "6146"; setItem(item, obj2, obj); object obj3 = dpi; object obj4 = "6147"; setItem(item, obj4, obj3); object obj5 = dpi; object obj6 = "6148"; setItem(item, obj6, obj5); try { ImageFile imageFile = (ImageFile)commonDialog.ShowTransfer(item, "{00000000-0000-0000-0000-000000000000}", false); string tempFileName = Path.GetTempFileName(); if (File.Exists(tempFileName)) { File.Delete(tempFileName); } imageFile.SaveFile(tempFileName); Image img = Image.FromFile(tempFileName); EventHandler <WiaImageEventArgs> scanning = this.Scanning; if (scanning != null) { scanning(this, new WiaImageEventArgs(img)); } num2++; } catch (Exception ex) { throw ex; } finally { Property property = null; Property property2 = null; foreach (Property property3 in device2.Properties) { if ((long)property3.PropertyID == 3088L) { property = property3; } if ((long)property3.PropertyID == 3087L) { property2 = property3; } } flag = false; if (property != null) { if ((Convert.ToUInt32(property.get_Value()) & 1u) != 0u) { flag = ((Convert.ToUInt32(property2.get_Value()) & 1u) != 0u); } } num++; } } EventHandler scanComplete = this.ScanComplete; if (scanComplete != null) { scanComplete(this, EventArgs.Empty); } } }
void Scan(ScanColor clr, int dpi) { string deviceid; //Choose Scanner CommonDialogClass class1 = new CommonDialogClass(); Device d = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (d != null) { deviceid = d.DeviceID; } else { //no scanner chosen return; } WIA.CommonDialog WiaCommonDialog = new CommonDialogClass(); bool hasMorePages = true; int x = 0; int numPages = 0; while (hasMorePages) { //Create DeviceManager DeviceManager manager = new DeviceManagerClass(); 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! img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, 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 = 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 ArrayList ADFScan() { ArrayList dataArray = new ArrayList(); //Choose Scanner CommonDialogClass class1 = new CommonDialogClass(); // //class1.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); // Device d = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (d != null) { this.DeviceID = d.DeviceID; } else { //no scanner chosen return(new ArrayList()); } WIA.CommonDialog WiaCommonDialog = new CommonDialogClass(); bool hasMorePages = true; int x = 0; int numPages = 0; while (hasMorePages) { //Create DeviceManager DeviceManager manager = new DeviceManagerClass(); Device WiaDev = null; foreach (DeviceInfo info in manager.DeviceInfos) { if (info.DeviceID == this.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; try { img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, wiaFormatJPEG, false); //process image: //one would do image processing here // dataArray.Add(img); //Save to file //string varImageFileName = "c:\\test" + x.ToString() + ".jpg"; // if (File.Exists(varImageFileName)) // { // //file exists, delete it // File.Delete(varImageFileName); // } // img.SaveFile(varImageFileName); numPages++; img = null; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); } 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++; } } return(dataArray); }
/// <summary> /// Gets the device that will be used to acquire an image. /// </summary> private static WiaResult GetDevice(out Device device) { device = null; try { CommonDialogClass cdc = new CommonDialogClass(); device = cdc.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, false, false); if (device == null) //Either the user cancelled OR we have no device we can use to get an image. { return new WiaResult(string.Format(ERROR_MESSAGE_FORMAT, "get the capture device", "No device was selected")); } else { return WiaResult.Success; } } catch (COMException ce) { if (logger.IsDebugEnabled) { logger.Debug(WiaConstants.LoggingConstants.ExceptionOccurred, ce); } return new WiaResult(string.Format(ERROR_MESSAGE_FORMAT, "get the capture device", WiaError.GetErrorMessage(ce))); } }
/// <summary> /// Zeigt den Dialog zur Geräteauswahl an /// </summary> /// <returns>das Gerät, das der Benutzer ausgewählt hat</returns> public static Device FromUserDialog(WiaDeviceType deviceType = WiaDeviceType.UnspecifiedDeviceType, bool alwaysSelectDevice = false) { CommonDialogClass wiaDialog = new CommonDialogClass(); return(wiaDialog.ShowSelectDevice(deviceType, alwaysSelectDevice, false)); }
/// <summary> /// 扫描仪器 /// </summary> private void GetDevice() { // This will show the select device dialog to choose which device to use try { CommonDialogClass MyDialog = new CommonDialogClass(); //Device MyDevice = MyDialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, false, true); Device MyDevice = null; if (rdothers.Checked == true) { MyDevice = MyDialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, false, true); } //else if (MyDevice.Type == WIA.WiaDeviceType.CameraDeviceType) else if (rdothers.Checked == true) { MyDevice = MyDialog.ShowSelectDevice(WIA.WiaDeviceType.CameraDeviceType, false, true); // rdCamera.Checked = true; } if ((MyDevice != null)) { //loops through device properties, only gets the ones we want to display foreach (WIA.Property prop in MyDevice.Properties) { switch (prop.Name) { case "Manufacturer": lblMfg.Text = Convert.ToString(prop.get_Value()); break; case "Description": lblDesc.Text = Convert.ToString(prop.get_Value()); break; case "Name": lblName.Text = Convert.ToString(prop.get_Value()); break; case "WIA Version": lblWIA.Text = Convert.ToString(prop.get_Value()); break; case "Driver Version": lblDriver.Text = Convert.ToString(prop.get_Value()); break; } } //sets MyDevice form level selected device SelectedDevice = MyDevice; btncapture.Enabled = true; } else { lblName.Text = "No WIA Devices Found!"; MessageBox.Show("No WIA Devices Found!"); } } catch (System.Exception ex) { MessageBox.Show("Problem! " + ex.Message, "Problem Loading Device", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } }
void Scan(ScanColor clr, int dpi) { string deviceid; //Choose Scanner CommonDialogClass class1 = new CommonDialogClass(); Device d = class1.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (d != null) { deviceid = d.DeviceID; } else { //no scanner chosen return; } WIA.CommonDialog WiaCommonDialog = new CommonDialogClass(); bool hasMorePages = true; int x = 0; int numPages = 0; while (hasMorePages) { //Create DeviceManager DeviceManager manager = new DeviceManagerClass(); 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! img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, 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 = 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); } }
private void ScanDoc() { try { CommonDialogClass commonDialogClass = new CommonDialogClass(); Device scannerDevice = commonDialogClass.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); if (scannerDevice != null) { Item scannnerItem = scannerDevice.Items[1]; AdjustScannerSettings(scannnerItem, (int)nudRes.Value, 0, 0, (int)nudWidth.Value, (int)nudHeight.Value, 0, 0, cmbCMIndex); object scanResult = commonDialogClass.ShowTransfer(scannnerItem, WIA.FormatID.wiaFormatTIFF, false); //picScan.Image = (System.Drawing.Image)scanResult; if (scanResult != null) { ImageFile image = (ImageFile)scanResult; string fileName = ""; var files = Directory.GetFiles(txtPath.Text, "*.tiff"); try { string f = ((files.Max(p1 => Int32.Parse(Path.GetFileNameWithoutExtension(p1)))) + 1).ToString(); fileName = txtPath.Text + "\\" + f + ".tiff"; } catch (Exception ex) { fileName = txtPath.Text + "\\" + "1.tiff"; } SaveImageToTiff(image, fileName); picScan.ImageLocation = fileName; } } } catch(Exception err) { MessageBox.Show("Check the Device Connection \n or \n Change the Scanner Device", "Devic Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private object ZoomExecute() { try { var commonDialog = new CommonDialogClass(); Device d = commonDialog.ShowSelectDevice(WiaDeviceType.CameraDeviceType, true, false); } catch (Exception x) { if (x.Message.Contains(WiaError.ScannerNotAvailable)) { MessageBox.Show("No compatible device installed"); } } return null; }
/// <summary> /// Use scanner to scan an image (with user selecting the scanner from a dialog). /// </summary> /// <returns>Scanned images.</returns> public static string Scan() { ICommonDialog dialog = new CommonDialogClass(); var device = dialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, true, false); if (device != null) { return Scan(device.DeviceID); } else { throw new COMException("You must select a device for scanning."); } }