【问题标题】:How to scan all pages with one click as below:如何一键扫描所有页面如下:
【发布时间】:2019-11-18 11:57:17
【问题描述】:

我有下面的代码用于扫描所有文件。它可以工作,但问题是当所有论文都完成时,它会显示错误:

异常用户未处理的 System.runtime.InterpService.COMEException:来自 HRESULT 的异常:0*80210003

属于这一行的:

var imgFile = (ImageFile)ScanerItem.Transfer();

我该如何解决? 代码如下:

        public async void button1_Click(object sender, EventArgs e)
        {

                try
                {

                    object[] items = await Task.Run<object[]>(() =>
                    {

                        var deviceManager = new DeviceManager();
                        List<object> result = new List<object>();


                        for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++) // Loop Through the get List Of Devices.
                        {
                            if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
                            {
                                continue;
                            }
                            //new
                            result.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
                        }
                        return result.ToArray();


                    });

                    foreach (var item in items)
                    {
                        lstListOfScanner.Items.Add(item);
                    }

            }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.Message);
                }    
bool continueScanning2 = true;
    try
    {
        await Task.Run(() =>
        {
            var deviceManager = new DeviceManager();
            DeviceInfo AvailableScanner = null;
            while (continueScanning2)
            {

                string name2 = Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
                var Path = @"C:\Users\...\Desktop\test\" + name2; // save the image in some path with filename.
                pictureBox1.ImageLocation = Path;
                bitmap.Save(Path, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
        });
    }
    catch (COMException ex)
    {
        MessageBox.Show(ex.Message);
    }

【问题讨论】:

  • 听起来你需要检查scanneritem中的内容
  • @BugFinder 你知道怎么解决吗?
  • 试一试,如果退出检查有错误
  • 很遗憾,我找不到问题
  • 你需要提供比这更多的信息,试一试它会捕获错误并处理它 - 你还没有说你做了什么或它是如何改变的或任何东西

标签: c# c#-4.0 c#-3.0 scanning wia


【解决方案1】:

microsoft page 上提供的错误代码描述说

WIA_ERROR_PAPER_EMPTY

文档进纸器中没有文档。

并且您确认在扫描所有纸张时显示错误。

catch 块中,您可以检查错误代码并以您认为合适的方式处理遇到 WIA_ERROR_PAPER_EMPTY 错误的情况:

catch (COMException ex)
{
    uint errorCode = (uint)ex.ErrorCode;
    if (errorCode == 0x80210003)
    {
        // handle "There are no documents in the document feeder"
    }
    else
    {
        MessageBox.Show(ex.Message);
    }
}

【讨论】:

  • @arash6657,事实上,我已经冒险访问了一些有关 WIA 服务的在线资源,并意识到您提供的索引是正确的。不幸的是,我没有找到任何方法来检查扫描过程是否完成,因此处理异常和检查错误代码对我来说似乎是一种可能的解决方案,尽管我相信应该有其他选择。
  • 谢谢。这很好,但通常我们需要在扫描仪中没有纸张时看到警告。否则即使我没有将任何纸张放入扫描仪并按下按钮,我也不会通知。如果它有帮助,在我之前的代码中,它运行良好,但该代码的问题是:窗口在工作期间冻结(你也支持并修改了它)。您能否在下面的链接中查看之前的代码,看看是否有任何修复它的线索?谢谢。 stackoverflow.com/questions/58873895/…
猜你喜欢
  • 2012-11-15
  • 2012-06-30
  • 1970-01-01
  • 1970-01-01
  • 2017-03-10
  • 2022-01-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多