/// <summary> /// Start scan /// </summary> public void ScanAsync(ScannerInfo source) { if (source == null) { return; } var wiaDevice = source.GetDevice(); // Manager var wiaManager = new DeviceManager(); var hasMorePages = true; while (hasMorePages) { try { // Get items var wiaItem = wiaDevice.Items[1]; int inColor = 2, dpi = 300; wiaItem.Properties["6146"].set_Value(inColor); //Item MUST be stored in a variable THEN the properties must be set. wiaItem.Properties["6147"].set_Value(dpi); wiaItem.Properties["6148"].set_Value(dpi); // var imageFile = (ImageFile)(new CommonDialog()).ShowTransfer(wiaItem, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", false); //wiaItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") as WIA.ImageFile; var imageFile = wiaItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") as ImageFile; if (ScanCompleted != null) { ScanCompleted(this, new ScanCompletedEventArgs(imageFile.FileData.get_BinaryData())); } } catch (Exception) { break; } }
/// <summary> /// Scan a single image /// </summary> public byte[] ScanSingle(ScannerInfo source) { WIA.Device wiaDevice = source.GetDevice(); // Manager WIA.DeviceManager wiaManager = new WIA.DeviceManager(); try { // Get items WIA.Item wiaItem = wiaDevice.Items[1]; int inColor = 2, dpi = 300; wiaItem.Properties["6146"].set_Value((int)inColor);//Item MUST be stored in a variable THEN the properties must be set. wiaItem.Properties["6147"].set_Value(dpi); wiaItem.Properties["6148"].set_Value(dpi); var imageFile = (ImageFile)(new CommonDialog()).ShowTransfer(wiaItem, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", false); //wiaItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") as WIA.ImageFile; return(imageFile.FileData.get_BinaryData()); } catch (Exception e) { throw; } }
/// <summary> /// Start scan /// </summary> public void ScanAsync(ScannerInfo source) { if (source == null) { return; } WIA.Device wiaDevice = source.GetDevice(); // Manager WIA.DeviceManager wiaManager = new WIA.DeviceManager(); bool hasMorePages = true; while (hasMorePages) { try { // Get items WIA.Item wiaItem = wiaDevice.Items[1]; int inColor = 2, dpi = 300; wiaItem.Properties["6146"].set_Value((int)inColor); //Item MUST be stored in a variable THEN the properties must be set. wiaItem.Properties["6147"].set_Value(dpi); wiaItem.Properties["6148"].set_Value(dpi); // var imageFile = (ImageFile)(new CommonDialog()).ShowTransfer(wiaItem, "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}", false); //wiaItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") as WIA.ImageFile; var imageFile = wiaItem.Transfer("{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}") as WIA.ImageFile; if (this.ScanCompleted != null) { this.ScanCompleted(this, new ScanCompletedEventArgs(imageFile.FileData.get_BinaryData())); } } catch (Exception) { break; } finally { //determine if there are any more pages waiting WIA.Property documentHandlingSelect = null; WIA.Property documentHandlingStatus = null; foreach (WIA.Property prop in wiaDevice.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); } } if (hasMorePages && this.SingleOnly) { hasMorePages = false; } } } }