2012-03-06 107 views
0

我想掃描多個文檔。我已經編寫了掃描代碼,但我不知道如何在c#中掃描多個文檔。使用WIA掃描多個文檔

private void BtnScan_Click(object sender, EventArgs e) 
    { 
     // Scanner selected? 
     var device = Devices.SelectedItem as Scanner; 
     if (device == null) 
     { 
      MessageBox.Show("Please select a device.", "Warning", 
          MessageBoxButtons.OK, MessageBoxIcon.Warning); 
      return; 
     } 
Devices.SelectedIndex = 0; 
     var image = device.Scan(); 
    // Scan 
     var image = device.Scan(); 

     // Save the image 
      var path = @"c:\scan.jpeg"; 
     if (File.Exists(path)) 
     { 
      File.Delete(path); 
     } 
     image.SaveFile(path); 
    } 

回答

0

您可以修改代碼,只要用戶想要繼續掃描,象這樣的:

//Initialization... 
bool continueScanning = true; 
while(continueScanning) 
{ 
    //Scan and save (modify path accordingly) 
    continueScanning = (MessageBox.Show("Continue scanning?", "Scan", MessageBoxButton.YesNo) == MessageBoxResult.Yes); 
} 
1
bool hasMorePages = true; 
int numPages = 0; 
while (hasMorePages) 
{ 
    WIA.ImageFile img = null; 
    WIA.Item Item = WiaDev.Items[1] as WIA.Item; 

    img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, wiaFormatJPEG, false); 


    //process image here 

    //maybe save to file 

    numPages++; 
    img = null; 
    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; 
    if (documentHandlingSelect != null) 
    { 
     //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); 
     } 
    } 

} 
+0

我將此添加到我的代碼我收到以下錯誤:錯誤名稱'WiaDev'在當前錯誤2中不存在名稱'WiaCommonDialog'在當前上下文中不存在\t錯誤名稱'wiaFormatJPEG'在當前上下文中不存在Error4名「WiaDev」不在當前上下文中錯誤存在\t 5:「WIA_DPS_DOCUMENT_HANDLING_SELECT」名稱不在當前上下文中存在\t錯誤「WIA_DPS_DOCUMENT_HANDLING_STATUS」名稱不在當前上下文中,當然 – chandrasekhar 2012-03-06 11:11:51

+0

,這可以存在不會被複制/粘貼,這是一個例子 – vulkanino 2012-03-06 14:36:18