void scan(string scannerId) { scanner = null; foreach (WIA.DeviceInfo devInfo in manager.DeviceInfos) { if (devInfo.DeviceID == scannerId) { scanner = devInfo.Connect(); } } if (scanner == null) { throw new Exception("Selected scanner is unavailable!"); } WIA.Item item = scanner.Items[1]; try { commonDialog = null; commonDialog = new WIA.CommonDialog(); scanInit(); scannedImage = (WIA.ImageFile)commonDialog.ShowTransfer(item, wiaFormatBMP, false); imageBytes = (byte[])scannedImage.FileData.get_BinaryData(); MemoryStream ms = new MemoryStream(imageBytes); image = Image.FromStream(ms); pbScannedImage.Image = image; } catch (Exception e) { throw e; } finally { Marshal.ReleaseComObject(scannedImage); } }
private void buttonChooseScanner_Click(object sender, EventArgs e) { commonDialog = new WIA.CommonDialog(); scanner = commonDialog.ShowSelectDevice(WIA.WiaDeviceType.UnspecifiedDeviceType, true, false); }