我是silverlight的新手,我正在尝试使用wia扫描仪集成。我知道WIA.CommonDialog,showacquireimage()我可以从扫描仪中检索图像。我试图直接访问设备并执行scan命令以避免用户交互。
我可以连接到设备。但扫描仪唯一可用的命令是同步。我试图在设备对象上使用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();
}
}
}
}
答案 0 :(得分: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#。也许它可以在你的项目中派上用场,你将完成几行代码,包括设置基本属性。 :)