private WIA.Item GetScanningProperties(bool showUI, CommonDialogClass wiaCommonDialog, Device WiaDev) { WIA.Items items = null; if (showUI) { try { items = wiaCommonDialog.ShowSelectItems(WiaDev, WiaImageIntent.TextIntent, WiaImageBias.MinimizeSize, false, true, false); } catch (Exception) { } } else { items = WiaDev.Items; } WIA.Item scanningItem = null; if (items != null && items.Count > 0) { scanningItem = items[1] as WIA.Item; } return(scanningItem); }
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); }