我是silverlight的新手,我正在试验wia扫描仪的集成。我知道使用WIA.CommonDialog ()可以从扫描仪中检索图像。我试图直接访问设备并执行扫描命令以避免用户交互。
我能连接到这个设备。但是扫描仪中唯一可用的命令是同步。我试图在设备对象上使用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();
}
}
}
}发布于 2011-06-09 09:46:26
您实际上不需要处理设备命令来扫描文档。相反,您需要使用设备对象下的第一个设备项。下面是一个简单的示例,它本身是有效的,不需要进行失败检查以获得更容易的可读性。
//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框架2.0,C#。也许它会在您的项目中派上用场,您可以完成几行代码,包括设置基本属性。:)
https://stackoverflow.com/questions/4357448
复制相似问题