2013-09-06 3 views
0

C#에서 하나의 창 응용 프로그램을 개발 중입니다. 이를 위해, WIA & 드라이버를 "http://www.fujitsu.com/global/support/computing/peripheral/scanners/drivers/twain/v9211307.html" - "Ft9l10bX5.exe"에서 가져옵니다.C# fujistu fi-6140 스캐너 값이 예상 범위를 벗어납니다.

내 코드 :

class WIAScanner 
    { 
     const string wiaFormatBMP = "{B96B3CAB-0728-11D3-9D7B-0000F81EF32E}"; 

     class WIA_DPS_DOCUMENT_HANDLING_SELECT 
     { 
      public const uint FEEDER = 0x00000001; 
      public const uint FLATBED = 0x00000002; 
     } 

     class WIA_DPS_DOCUMENT_HANDLING_STATUS 
     { 
      public const uint FEED_READY = 0x00000001; 
     } 

     class WIA_PROPERTIES 
     { 
      public const uint WIA_RESERVED_FOR_NEW_PROPS = 1024; 
      public const uint WIA_DIP_FIRST = 2; 
      public const uint WIA_DPA_FIRST = WIA_DIP_FIRST + WIA_RESERVED_FOR_NEW_PROPS; 
      public const uint WIA_DPC_FIRST = WIA_DPA_FIRST + WIA_RESERVED_FOR_NEW_PROPS; 
      // 
      // Scanner only device properties (DPS) 
      // 
      public const uint WIA_DPS_FIRST = WIA_DPC_FIRST + WIA_RESERVED_FOR_NEW_PROPS; 
      public const uint WIA_DPS_DOCUMENT_HANDLING_STATUS = WIA_DPS_FIRST + 13; 
      public const uint WIA_DPS_DOCUMENT_HANDLING_SELECT = WIA_DPS_FIRST + 14; 
     } 

     /// <summary> 
     /// Use scanner to scan an image (with user selecting the scanner from a dialog). 
     /// </summary> 
     /// <returns>Scanned images.</returns> 
     public static List<Image> Scan() 
     { 
      WIA.ICommonDialog dialog = new WIA.CommonDialog(); 
      WIA.Device device = dialog.ShowSelectDevice(WIA.WiaDeviceType.UnspecifiedDeviceType, true, false); 

      if (device != null) 
      { 
       return Scan(device.DeviceID); 
      } 
      else 
      { 
       throw new Exception("You must select a device for scanning."); 
      } 
     } 

     /// <summary> 
     /// Use scanner to scan an image (scanner is selected by its unique id). 
     /// </summary> 
     /// <param name="scannerName"></param> 
     /// <returns>Scanned images.</returns> 
     public static List<Image> Scan(string scannerId) 
     { 
      List<Image> images = new List<Image>(); 

      bool hasMorePages = true; 
      while (hasMorePages) 
      { 
       // select the correct scanner using the provided scannerId parameter 
       WIA.DeviceManager manager = new WIA.DeviceManager(); 
       WIA.Device device = null; 
       foreach (WIA.DeviceInfo info in manager.DeviceInfos) 
       { 
        if (info.DeviceID == scannerId) 
        { 
         // connect to scanner 
         device = info.Connect(); 
         break; 
        } 
       } 

       // device was not found 
       if (device == null) 
       { 
        // enumerate available devices 
        string availableDevices = ""; 
        foreach (WIA.DeviceInfo info in manager.DeviceInfos) 
        { 
         availableDevices += info.DeviceID + "\n"; 
        } 

        // show error with available devices 
        throw new Exception("The device with provided ID could not be found. Available Devices:\n" + availableDevices); 
       } 

       WIA.Item item = device.Items[1] as WIA.Item; 

       try 
       { 
        // scan image 
        WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog(); 
        WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false); 

        // save to temp file 
        string fileName = Path.GetTempFileName(); 

       } 
       catch (Exception exc) 
       { 
        throw exc; 
       } 
       finally 
       { 
        item = null; 

        //determine if there are any more pages waiting 
        WIA.Property documentHandlingSelect = null; 
        WIA.Property documentHandlingStatus = null; 

        foreach (WIA.Property prop in device.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; 
        } 

        // assume there are no more pages 
        hasMorePages = false; 

        // may not exist on flatbed scanner but required for feeder 
        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); 
         } 
        } 
       } 
      } 

      return images; 
     } 

    } 

지금 문제는 : 내가 fijustu의 FI-6140 (낱장 공급 스캐너)와 함께 노력하고 때"평판 스캐너"에 잘 작동하지만입니다. 그것은 나를 보여주는 오류 :

"값이 예상 된 범위 내에 있지 않습니다." 이 줄의 : "WIA.ImageFile image = (WIA.ImageFile) wiaCommonDialog.ShowTransfer (item, wiaFormatBMP, false);"

내가 누락 된 구성을 알려주십시오.

답변

0

필자는 fi-6310z에서 같은 문제가 발생했습니다. 알아내는 데는 시간이 걸렸지 만 장치의 페이지 속성 (장치 속성 ID 3096)을 사용하는 것이 문제 인 것 같습니다. 기본적으로 0으로 설정되어있는 것 같습니다. 수동으로 1로 설정하면 ShowTransfer가 정상적으로 작동합니다. 내가 설명한 방법이 내 스캐너에서 작동하지 않기 때문에 (문서 처리 상태는 항상 5입니다.) 이것이 더 많은 페이지가 있는지 여부를 결정하는 방법에 영향을 줄지 확실하지 않습니다.

+0

fi-6130Z에서 같은 문제가 발생합니다. 수정 코드가 있습니까? –

관련 문제