如何通过单击一下来扫描所有页面,如下所示:

问题描述 投票:0回答:1

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

异常用户未经处理的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)
            {
                for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
                {
                    if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType) // Skip device If it is not a scanner
                    {
                        continue;
                    }
                    AvailableScanner = deviceManager.DeviceInfos[i];
                    break;
                }
                var device = AvailableScanner.Connect();
                var ScanerItem = device.Items[1];
                var imgFile = (ImageFile)ScanerItem.Transfer();
                var data = (byte[])imgFile.FileData.get_BinaryData();
                var bitmap = GetBitmapFromRawData(imgFile.Width, imgFile.Height, data);
                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);
    }
c# c#-4.0 scanning
1个回答
0
投票

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

WIA_ERROR_PAPER_EMPTY

文档进纸器中没有文档。

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

目前尚不清楚ScanerItem实现是什么,也许有某种属性可以检查并确定过程是否完成。

否则,应捕获此类代码的异常,并且不向用户显示。

© www.soinside.com 2019 - 2024. All rights reserved.