我遇到以下代码的问题。我想通过单击WinForms C#应用程序中的按钮来扫描文档。
我使用WIA,Visual studio和使用Windows 8的扫描仪Fujitsu N7100A。我正在使用WIA在线教程。
但该计划并未按预期运行。它似乎在转移方法中被打破了。
// Create a DeviceManager instance
var deviceManager = new DeviceManager();
// Create an empty variable to store the scanner instance
DeviceInfo firstScannerAvailable = null;
// Loop through the list of devices to choose the first available
AddLogs(deviceManager.DeviceInfos.Count.ToString(), filename);
foreach (DeviceInfo d in deviceManager.DeviceInfos)
{
if (d.Type == WiaDeviceType.ScannerDeviceType)
{
firstScannerAvailable = d;
}
}
// Connect to the first available scanner
var device = firstScannerAvailable.Connect();
// Select the scanner
var scannerItem = device.Items[0];
// Retrieve a image in JPEG format and store it into a variable
var imageFile = (ImageFile)scannerItem.Transfer(FormatID.wiaFormatPNG);
//Save the image in some path with filename
var path = @"C:\Documents\scan.png";
if (File.Exists(path))
{
File.Delete(path);
}
// Save image !
imageFile.SaveFile(path);
我只需删除日志文件中添加的行。
答案 0 :(得分:0)
这是一种解决方法,因为我不知道你的扫描仪。
我会假设所有扫描仪都有一个存储扫描文档的驱动器,就像我的一样。所以我建议你读取所有可用的驱动器循环检查DriveType和VolumeLabel,然后读取它的文件并将文件复制到哪里你想要
这样的事情:
foreach (var item in DriveInfo.GetDrives())
{
//VolumeLabel differs from a scanner to another
if (item.VolumeLabel == "Photo scan" && item.DriveType == DriveType.Removable)
{
foreach (var obj in Directory.GetFiles(item.Name))
{
File.Copy(obj, "[YOUR NEW PATH]");
break;
}
break;
}
}
答案 1 :(得分:0)
最终TWAIN应用程序可与此扫描仪配合使用。我将与之合作。我不知道为什么这样做与TWAIN合作而不是与WIA合作,而是现实。对不起浪费时间。谢谢你的答案。祝你有愉快的一天。
答案 2 :(得分:0)
我目前正在解决这个问题。看起来N7100A驱动程序将Pages
的{{1}}属性设置为device
,这应该意味着连续扫描,但是传输方法无法处理该值。您必须将该属性设置为0
:
1