2010-12-05 6 views
0

私は銀色の新人です。私はwiaスキャナの統合を試しています。私はWIAを知っている。CommonDialog、showacquireimage()私はスキャナから画像を取得することができます。私はデバイスに直接アクセスし、ユーザーのやり取りを避けるためにスキャンコマンドを実行しようとしています。WIA silverlight Scanner integration

デバイスに接続できます。しかし、スキャナから利用できる唯一のコマンドは同期です。デバイスオブジェクトで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#用です。おそらくそれはあなたのプロジェクトに役立つかもしれません、あなたは基本的なプロパティを設定することを含むコードのいくつかの行で行われるでしょう。 :)