c# - 在 Windows 7 上使用 WIA 扫描多个页面
问题描述
我正在尝试从进纸器扫描几页,尽管当我调用 ShowTransfer 函数(不使用循环)时扫描仪会自动扫描所有页面,但我只取回第一页。
我究竟做错了什么?
这是我的代码:
WIA.Item item = device.Items[1] as WIA.Item;
if (pages > 1)
{
// Set to feeder
SetWIAProperty(device.Properties, 44, 1);
}
SetWIAProperty(device.Properties, WIA_DEVICE_PROPERTY_PAGES_ID, 1);
AdjustScannerSettings(item, 150, 0, 0, 1250, 1700, 0, 0, 1);
try
{
// scan image
WIA.ICommonDialog wiaCommonDialog = new WIA.CommonDialog();
WIA.ImageFile image = (WIA.ImageFile)wiaCommonDialog.ShowTransfer(item, wiaFormatBMP, false);
// save to temp file
string fileName = Path.GetTempFileName();
File.Delete(fileName);
image.SaveFile(fileName);
image = null;
// add file to output list
images.Add(Image.FromFile(fileName));
}
catch (Exception exc)
{
throw exc;
}
解决方案
我认为这个链接正在做你想做的事
http://forums.codeguru.com/showthread.php?439027-Windows-Image-Acquisition-(WIA)-代码
基本上,您需要在保存每个页面后检查以查看是否还有更多页面并保持循环
hasMorePages = false; //assume there are no more pages
if (documentHandlingSelect != null)
//may not exist on flatbed scanner but required for feeder
{
//check for document feeder
if ((Convert.ToUInt32(documentHandlingSelect.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_SELECT.FEEDER) != 0)
{
hasMorePages = ((Convert.ToUInt32(documentHandlingStatus.get_Value()) & WIA_DPS_DOCUMENT_HANDLING_STATUS.FEED_READY) != 0);
}
}
推荐阅读
- google-tag-manager - 如何在跟踪事件时包含 cookie-id
- python - 在scrapy中获取重定向的url时出错:Python
- c# - Windows 窗体从数据库中获取数据并显示在标签中
- javafx - JavaFX:更新一个列表中的 Part 属性会更新另一个列表
- ios - 替换 UIStackView 中的视图
- optimization - 使用 CVXOPT 进行大量变量的二次规划
- python-3.x - 无法安装 matplotlib 也无法升级 pip
- nstablerowview - 如何像 Xcode IB 对象选择器一样实现 NSTableViewRowlView
- android - 在 Android 中模拟 Socket 服务器
- html - 顶部对齐文本与旁边的固定图像?