private void Button_Click_1(object sender, RoutedEventArgs e) { try { using (dynamic CommonDialog = AutomationFactory.CreateObject("WIA.CommonDialog")) { dynamic imageFile = CommonDialog.ShowAcquireImage(); if (imageFile != null) { if (!Directory.Exists("D:\\ScanImage")) { Directory.CreateDirectory("D:\\ScanImage"); } string filePath = string.Format("D:\\ScanImage\\{0}.jpg", Guid.NewGuid()); imageFile.SaveFile(filePath); } } } catch (System.Runtime.InteropServices.COMException ex) { if (ex.ErrorCode == -2145320939) { MessageBox.Show("Could not find an attached scanner.", "Scanner Error", MessageBoxButton.OK); } else { MessageBox.Show(ex.Message, "Scanner Error", MessageBoxButton.OK); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)