使用WIA扫描多个文档
问题描述:
我想扫描多个文档。我已经编写了扫描代码,但我不知道如何在c#中扫描多个文档。使用WIA扫描多个文档
private void BtnScan_Click(object sender, EventArgs e)
{
// Scanner selected?
var device = Devices.SelectedItem as Scanner;
if (device == null)
{
MessageBox.Show("Please select a device.", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Devices.SelectedIndex = 0;
var image = device.Scan();
// Scan
var image = device.Scan();
// Save the image
var path = @"c:\scan.jpeg";
if (File.Exists(path))
{
File.Delete(path);
}
image.SaveFile(path);
}
答
您可以修改代码,只要用户想要继续扫描,象这样的:
//Initialization...
bool continueScanning = true;
while(continueScanning)
{
//Scan and save (modify path accordingly)
continueScanning = (MessageBox.Show("Continue scanning?", "Scan", MessageBoxButton.YesNo) == MessageBoxResult.Yes);
}
答
bool hasMorePages = true;
int numPages = 0;
while (hasMorePages)
{
WIA.ImageFile img = null;
WIA.Item Item = WiaDev.Items[1] as WIA.Item;
img = (ImageFile)WiaCommonDialog.ShowTransfer(Item, wiaFormatJPEG, false);
//process image here
//maybe save to file
numPages++;
img = null;
Item = null;
//determine if there are any more pages waiting
Property documentHandlingSelect = null;
Property documentHandlingStatus = null;
foreach (Property prop in WiaDev.Properties)
{
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
documentHandlingSelect = prop;
if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
documentHandlingStatus = prop;
}
hasMorePages = false;
if (documentHandlingSelect != null)
{
//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);
}
}
}
我将此添加到我的代码我收到以下错误:错误名称'WiaDev'在当前错误2中不存在名称'WiaCommonDialog'在当前上下文中不存在\t错误名称'wiaFormatJPEG'在当前上下文中不存在Error4名“WiaDev”不在当前上下文中错误存在\t 5:“WIA_DPS_DOCUMENT_HANDLING_SELECT”名称不在当前上下文中存在\t错误“WIA_DPS_DOCUMENT_HANDLING_STATUS”名称不在当前上下文中,当然 – chandrasekhar 2012-03-06 11:11:51
,这可以存在不会被复制/粘贴,这是一个例子 – vulkanino 2012-03-06 14:36:18