2010-12-05 3 views
0

저는 실버 라이트를 처음 사용하기 때문에 wia 스캐너 통합을 실험하고 있습니다. WIA를 사용하고 있습니다. 공용 다이얼로그, showacquireimage() 스캐너에서 이미지를 가져올 수 있습니다. 장치에 직접 액세스하고 사용자 상호 작용을 피하기 위해 스캔 명령을 실행하려고합니다.WIA 실버 라이트 스캐너 통합

기기에 연결할 수 있습니다. 그러나 스캐너에서 사용할 수있는 유일한 명령은 동기화입니다. 장치 개체에 ExecuteCommand를 사용하려고하지만 사용하려는 명령이 확실하지 않습니다. 모든 방향을 이해할 것입니다.

 using (dynamic DeviceManager1 = AutomationFactory.CreateObject("WIA.DeviceManager")) 
     { 
      var deviceInfos = DeviceManager1.DeviceInfos; 
      for(int i= 1;i<=deviceInfos.Count;i++) 
      { 
       //check if the device is a scanner 
       if (deviceInfos.Item(i).Type.ToString() == "1") 
       { 
        var IDevice = deviceInfos.Item(i).Connect(); 
        deviceN.Text = IDevice.Properties("Name").Value.ToString(); 

        var dv = IDevice.Commands; 
        for (int j = 0; j <= dv.Count; j++) 
        { 

         deviceN.Text += " " + dv.Item(i).CommandID.ToString() + " " + dv.Item(i).Description.ToString(); 
        } 

       } 

      }    
     } 

답변

1

문서를 스캔하려면 장치 명령을 처리 할 필요가 없습니다. 대신 장치 개체 아래에 첫 번째 장치 항목을 사용해야합니다. 다음은 가독성을 위해 오류 검사없이 그 자체로 작동하는 작은 예제입니다. (당신이 장치 항목에 연결 한 후에 만)

//using WIA; 

bool showProgressBar = false; 

DeviceManager deviceManager = new DeviceManagerClass(); 

foreach(DeviceInfo info in deviceManager.DeviceInfos) 
{ 
    if(info.Type == WiaDeviceType.ScannerDeviceType) 
    { 
     Device device = info.Connect(); 

     ImageFile imageFile = null; 

     Item deviceItem = null; 

     //Read through the list of items under the device... 
     foreach(Item item in device.Items) 
     { 
      //Pick the very first one! 
      deviceItem = item; 
      break; 
     } 

     if(showProgressBar == true) 
     { 
      //Scan without GUI, but display the progress bar dialog. 
      CommonDialogClass commonDialog = new CommonDialogClass(); 
      imageFile = (ImageFile)commonDialog.ShowTransfer(deviceItem, FormatID.wiaFormatBMP, false); 
     } 
     else 
     { 
      //Scan without GUI, no progress bar displayed... 
      imageFile = (ImageFile)deviceItem.Transfer(FormatID.wiaFormatBMP); 
     } 

     imageFile.SaveFile("C:\\image.bmp"); 
    } 
} 

스캔하기 전에, 당신은 아마 기본값이 사용자의 요구에 충분하지 않은 경우 스캔 해상도, 색상 및 기타 물건을 선택하는 다양한 장치 속성을 설정해야합니다.

얼마 전에 WIA 호환 스캐너를 사용하기 쉬운 클래스를 만들었습니다. this page에서 다운로드 할 수 있습니다. .Net Framework 2.0, C# 용입니다. 아마도 프로젝트에 유용 할 수 있습니다. 기본 속성 설정을 포함하여 몇 줄의 코드를 사용하면됩니다. :)