0

私はSilverlightを初めて使用し、wiaスキャナーの統合を実験しています。WIA.CommonDialog、showacquireimage()を使用して、スキャナーから画像を取得できることを知っています。ユーザーの操作を避けるために、デバイスに直接アクセスしてスキャンコマンドを実行しようとしています。

デバイスに接続できます。ただし、スキャナーから使用できるコマンドは同期のみです。デバイスオブジェクトで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();
                    }

                }

            }            
        }
4

1 に答える 1

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互換のスキャナーを操作するための使いやすいクラスを作成しました。このページからダウンロードできます...これは.Net Framework 2.0、C#用です。プロジェクトで役立つかもしれませんが、基本的なプロパティの設定を含む数行のコードで完了します。:)

于 2011-06-09T09:46:26.177 に答える