2012-03-06 2 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'이름이 현재 Error2The에 없습니다. 'WiaCommonDialog'이 (가) 현재 컨텍스트에 존재하지 않습니다. \t 오류 'wiaFormatJPEG'라는 이름이 현재 컨텍스트에 없습니다. Error4 이름은 'WiaDev'현재 컨텍스트 오류에 존재하지 않는 \t 5 : 이름 'WIA_DPS_DOCUMENT_HANDLING_SELECT'는 현재 컨텍스트에 이름 'WIA_DPS_DOCUMENT_HANDLING_STATUS'는 현재 컨텍스트 물론 – chandrasekhar

+0

,이 수에 존재하지 않는 \t 오류가 존재하지 않습니다 복사/붙여 넣기가 가능한 예입니다. – vulkanino