微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

异常错误HRESULT E_FAIL已从对COM组件的调用返回 WIA扫描仪C#

如何解决异常错误HRESULT E_FAIL已从对COM组件的调用返回 WIA扫描仪C#

我希望有人遇到过这种情况-我正在尝试使用WIA从文档扫描仪捕获图像,我想使用FeedER进行多篇论文,并且我正在使用发生错误代码和以下代码: 我能够成功连接到扫描仪,查询名称,制造商等。

            {
            int pages = 0;
            bool hasMorePages = false;
            string[] sourceFiles = new string[100];

            WIA.CommonDialog WiaCommonDialog = new WIA.CommonDialog();

            try
            {
                do
                {
                    //Connect to Device
                    Device wia = Connect();
                    WIA.Item item = wia.Items[1] as WIA.Item;

                    //Setup ADF
                    if ((useAdf) || (duplex))
                        SetupADF(wia,duplex);

                    //Setup Page Size
                    //  SetupPageSize(wia,rotatePage,A4,DPI,item);

                    WIA.ImageFile imgFile = null;
                    WIA.ImageFile imgFile_duplex = null; //if duplex is setup,this will be back page

                    //imgFile = (WIA.ImageFile)item.Transfer(WIA.FormatID.wiaFormatJPEG);


                    imgFile = (ImageFile)WiaCommonDialog.ShowTransfer(item,wiaFormatJPEG,false);

                    //If duplex page,get back page Now.
                    if (duplex)
                    {
                        imgFile_duplex = (ImageFile)WiaCommonDialog.ShowTransfer(item,false);
                    }

                    string varImageFileName = filepath + "\\Scanned" + ".jpeg";

                    Delete_File(varImageFileName); //if file already exists. delete it.
                    imgFile.SaveFile(varImageFileName);

                    using (var src = new System.Drawing.Bitmap(varImageFileName))
                    using (var bmp = new System.Drawing.Bitmap(1000,1000,System.Drawing.Imaging.PixelFormat.Format32bppPArgb))
                    using (var gr = system.drawing.graphics.FromImage(bmp))
                    {
                        gr.Clear(System.Drawing.Color.Blue);
                        gr.DrawImage(src,new System.Drawing.Rectangle(0,bmp.Width,bmp.Height));
                        gr.DrawString("This is vivek",new System.Drawing.Font("Arial",15,System.Drawing.FontStyle.Regular),System.Drawing.SystemBrushes.WindowText,new System.Drawing.Point(550,20));
                        bmp.Save(System.Configuration.ConfigurationSettings.AppSettings["Path"] + "test" + pages + ".jpeg",System.Drawing.Imaging.ImageFormat.Png);

                        ////string imgPath = "test" + pages + ".tiff";
                        ////sourceFiles[pages] = imgPath;
                        //mergeTiffPages(string str_DestinationPath,string[] sourceFiles)
                    }
                    mergeTiffPages(@"D:\Test\",sourceFiles);

                    string varImageFileName_duplex;

                    if (duplex)
                    {
                        varImageFileName_duplex = filepath + "\\Scanned-" + pages.ToString() + ".tiff";
                        Delete_File(varImageFileName_duplex); //if file already exists. delete it.
                        imgFile_duplex.SaveFile(varImageFileName);
                    }

                    //Check with scanner to see if there are more pages.
                    if (useAdf || duplex)
                    {
                        hasMorePages = HasMorePages(wia);
                        pages++;
                    }
                }

                while (hasMorePages);
            }
            catch (System.Runtime.InteropServices.COMException ex)
            {
                //throw new System.Exception(Checkerror((uint)ex.ErrorCode));
            }
        }

此行引发异常

                    imgFile = (ImageFile)WiaCommonDialog.ShowTransfer(item,false);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。