[英]Scan multiple documents using WIA
I want to scan multiple documents. 我想扫描多个文件。 And I have written the code for scanning but i am not getting idea how to scan multiple documents in c#.
而且我已经编写了用于扫描的代码,但是我不知道如何在c#中扫描多个文档。
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);
}
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);
}
}
}
You can modify your code to continue scanning as long as the user wants that like that: 您可以修改代码以继续扫描,只要用户希望这样:
//Initialization...
bool continueScanning = true;
while(continueScanning)
{
//Scan and save (modify path accordingly)
continueScanning = (MessageBox.Show("Continue scanning?", "Scan", MessageBoxButton.YesNo) == MessageBoxResult.Yes);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.