1

我只能扫描文档的一面,而不能扫描第二面。使用 Wia Leadtools 实现双面扫描需要哪些设置。

WiaAcquireFlags flags = WiaAcquireFlags.None;
bool showProgress = true;
_progressDlg = new ProgressForm("Transferring", "", 100);
_wiaAcquiring = true;                   

if (_showUserInterface)
{
    flags = WiaAcquireFlags.UseCommonUI | WiaAcquireFlags.ShowUserInterface;
}
else
{
    if (SelectAcquireSource() != System.Windows.Forms.DialogResult.OK)
    {
        _wiaAcquiring = false;
        return;
    }
}

if (_showUserInterface && _wiaVersion == WiaVersion.Version2)
    showProgress = false;

if (showProgress)
    _progressDlg.Show();

_wiaSession.AcquireOptions = _wiaAcquireOptions;
_transferMode = (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) ? WiaTransferMode.Memory : _wiaProperties.DataTransfer.TransferMode;


//#if !LEADTOOLS_V19_OR_LATER
System.Windows.Forms.DialogResult dialogResult = _wiaSession.Acquire(mainWindowHandle, _sourceItem, flags);

更新代码:,我根据“LEADTOOLS Support”的回答更新了代码,但它仍在扫描页面的一侧。

public void Scan()
{
    ...
    ...
    ...
    object rootItem = _wiaSession.GetRootItem(null);
    if (rootItem != null)
    {
     wiaSession.EnumItemsEvent += new EventHandler<WiaEnumItemsEventArgs>       (wiaSession_EnumItemsEvent);    
     wiaSession.EnumChildItems(rootItem);
     wiaSession.EnumItemsEvent -= new EventHandler<WiaEnumItemsEventArgs>(wiaSession_EnumItemsEvent);

     wiaSession.AcquireOptions = _wiaAcquireOptions;
     transferMode = (_wiaProperties.DataTransfer.TransferMode == WiaTransferMode.None) ? WiaTransferMode.Memory : _wiaProperties.DataTransfer.TransferMode;

    //#if !LEADTOOLS_V19_OR_LATER
      System.Windows.Forms.DialogResult dialogResult = _wiaSession.Acquire(mainWindowHandle, _sourceItem, flags);

    ...
    ...
    ...
}
public void wiaSession_EnumItemsEvent(object sender, WiaEnumItemsEventArgs e)
{
   if (e.Item != null)
   {               

    WiaProperties wiaProperties = _wiaSession.GetProperties(e.Item);
        if (System.Windows.Forms.MessageBox.Show("Enable duplex?", "WIA test", System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
        {
           wiaProperties.ScanningMode = WiaScanningModeFlags.Feeder | WiaScanningModeFlags.Duplex;
           wiaProperties.MaximumNumberOfPages = 2;
        }
        else
        {
          wiaProperties.ScanningMode = WiaScanningModeFlags.Feeder | WiaScanningModeFlags.FrontOnly;
          wiaProperties.MaximumNumberOfPages = 1;
        }
          wiaSession.SetProperties(e.Item, wiaProperties);
     }
  }

注意:
- 我已经调试了代码,它在 wiaSession_EnumItemsEvent 中设置了属性
- 当它从“启用双工”询问时,我单击“是”
- 添加了用于设置属性的调试代码的屏幕截图
- 我在进纸器中有一张我想要的纸从两侧扫描

在此处输入图像描述

功能选项: 在此处输入图像描述

在此处输入图像描述

4

1 回答 1

0

假设您在进纸器中有 1 张纸,扫描两面的代码需要指定 2 页,每面一个。这可以使用 WiaProperties.MaximumNumberOfPages 属性来完成。然后使用 WiaProperties.ScanningMode 属性启用双面扫描。代码如下所示:

WiaProperties wiaProps = _wiaSession.GetProperties(wiaItem);
if (MessageBox.Show("Enable duplex?", "WIA test", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes)
{
   wiaProps.ScanningMode = WiaScanningModeFlags.Feeder | WiaScanningModeFlags.Duplex;
   wiaProps.MaximumNumberOfPages = 2;
}
else
{
   wiaProps.ScanningMode = WiaScanningModeFlags.Feeder | WiaScanningModeFlags.FrontOnly;
   wiaProps.MaximumNumberOfPages = 1;
}
_wiaSession.SetProperties(wiaItem, wiaProps);
于 2017-11-09T08:18:46.273 回答