WIA silverlight扫描仪集成
问题描述:
我是silverlight的新手,我正在尝试使用wia扫描仪集成。我知道usia WIA.CommonDialog,showacquireimage()我可以从扫描仪中检索图像。我试图直接访问设备并执行扫描命令以避免用户交互。WIA silverlight扫描仪集成
我可以连接到设备。但扫描仪可用的唯一命令是同步的。我试图在设备对象上使用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();
}
}
}
}
答
您并不需要处理设备命令来扫描文档。相反,您需要使用设备对象下的第一个设备项目。这里有一个小例子,它本身起作用,没有失败检查以便于阅读。
//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#。也许它可以方便地在你的项目中使用,你可以用几行代码完成,包括设置基本属性。 :)