【问题标题】:Unable to Scan using WIA on Windows 7 x64无法在 Windows 7 x64 上使用 WIA 进行扫描
【发布时间】:2014-01-05 07:40:15
【问题描述】:

错误信息:

无法加载文件或程序集“Interop.WIA,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null”或其依赖项之一。试图加载格式不正确的程序。

该解决方案在带有普通 USB 扫描仪的 Windows XP 上运行良好, 但是,在上面的 Windows 7 (x64) 上尝试使用网络扫描仪(使用 Scangear 工具发现)进行扫描时遇到了。

C#代码:

 private void startscan()
        {

            try
            {

                CommonDialogClass dailog = new CommonDialogClass();
                ImageFile imgfile = (ImageFile)dailog.ShowAcquireImage(WiaDeviceType.ScannerDeviceType, WiaImageIntent.UnspecifiedIntent, WiaImageBias.MaximizeQuality,
                FormatID.wiaFormatJPEG, true, true, false);
                string firstname = DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
                string name = scantxtfname.Text.Trim() + ".jpeg";


                string filenamepath = ConfigurationManager.ConnectionStrings["scanfilepath"].ConnectionString.ToString() + firstname + name;

                scanfile.Add(name);
                firstint.Add(Convert.ToInt32(firstname));
                SaveImageToPNGFile(imgfile, filenamepath);



                FileStream stream = new FileStream(filenamepath, FileMode.Open, FileAccess.Read);

                stream.Close();

                DataTable dt = new DataTable();

                dt.Columns.Add("Scaned Files", typeof(string));

                datagridscanedfiles.DataSource = null;

                for (int i = 0; i < scanfile.Count; i++)
                {
                    DataRow r = dt.NewRow();
                    r[0] = scanfile[i].ToString();
                    dt.Rows.Add(r);
                }
                datagridscanedfiles.DataSource = dt;
                datagridscanedfiles.Visible = true;
                int ln = scanfile.Count;

                pictureBox1.ImageLocation = filenamepath;

            }
            catch ( Exception d)
            {

                MessageBox.Show(d.Message);
            }


        }


 private static void SaveImageToPNGFile(ImageFile image, string fileName)
        {
            try
            {
                ImageProcess imgProcess = new ImageProcess();
                object convertFilter = "Convert";
                string convertFilterID = imgProcess.FilterInfos.get_Item(ref convertFilter).FilterID;
                imgProcess.Filters.Add(convertFilterID, 0);
                SetWIAProperty(imgProcess.Filters[imgProcess.Filters.Count].Properties, "FormatID", WIA.FormatID.wiaFormatJPEG);
                image = imgProcess.Apply(image);
                image.SaveFile(fileName);
            }
            catch (Exception er)
            {

                MessageBox.Show(er.Message);
            }

        }

  private static void SetWIAProperty(IProperties properties, object propName, object propValue)
        {
            Property prop = properties.get_Item(ref propName);

            prop.set_Value(ref propValue);
        }

请建议我如何解决上述问题?

【问题讨论】:

    标签: c# .net winforms wia image-scanner


    【解决方案1】:

    确保您没有将项目构建为“任何 CPU”。它必须是 x86。 WIA COM 组件无法在 64 位模式下运行。

    【讨论】:

      【解决方案2】:

      我也遇到过这个问题,更不能在X64平台编译成功。由于无法在 x64 模式下调用 WIA COM 组件,最后我只是转向另一种方式:在单个应用程序中完成您的 WIA 代码,然后使用另一个进程从您的主应用程序调用此扫描应用程序。我认为这不是最好的解决方案,但至少效果很好,哈哈。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-05-08
        • 2010-09-05
        • 2011-07-02
        • 2011-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-18
        相关资源
        最近更新 更多