使用WIA扫描多个文档

时间:2012-03-06 09:52:03

标签: c# winforms wia scanning

我想扫描多个文档。我已经编写了扫描代码,但我不知道如何在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);
    }

2 个答案:

答案 0 :(得分:1)

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);
        }
    }

}

答案 1 :(得分:0)

只要用户想要这样,您就可以修改代码以继续扫描:

//Initialization...
bool continueScanning = true;
while(continueScanning)
{
    //Scan and save (modify path accordingly)
    continueScanning = (MessageBox.Show("Continue scanning?", "Scan", MessageBoxButton.YesNo) == MessageBoxResult.Yes);
}