使用以下方法扫描应用程序时发生“ System.Runtime.InteropServices.COMException”错误

时间:2018-10-12 22:46:37

标签: c# .net

我编写了以下程序,但出现错误:

  

WindowsApplication.exe中出现了类型'System.Runtime.InteropServices.COMException'的第一次机会异常

namespace WindowApplication
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Scan_Click(object sender, EventArgs e)
        {

            //Scanner device = null;
            const string wiaFormatjpeg = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
            WIA.CommonDialog wiaDiag = new WIA.CommonDialog();

            WIA.ImageFile wiaImage = null;


            wiaImage = wiaDiag.ShowAcquireImage(

                    WiaDeviceType.UnspecifiedDeviceType,

                    WiaImageIntent.GrayscaleIntent,

                    WiaImageBias.MaximizeQuality,

                wiaFormatjpeg, true, true, false);
            WIA.Vector vector = wiaImage.FileData;



            Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
            i.Save(@"C:\Users\Desktop.jpeg");


        }
    }
} 

错误:

  

类型的第一次机会异常   发生“ System.Runtime.InteropServices.COMException”   WindowsFormsApplication4.exe

     

其他信息:错误HRESULT E_FAIL已从   调用COM组件。如果有针对此异常的处理程序,   该部分代码可以安全地继续执行程序

        wiaImage = wiaDiag.ShowAcquireImage(

                WiaDeviceType.UnspecifiedDeviceType,

                WiaImageIntent.GrayscaleIntent,

                WiaImageBias.MaximizeQuality,

                wiaFormatjpeg, true, true, false);
        WIA.Vector vector = wiaImage.FileData;

0 个答案:

没有答案