2013-12-17 182 views
0

错误味精到扫描:无法使用WIA在Windows 7 X64的

无法加载文件或程序集“Interop.WIA,版本= 1.0.0.0,文化=中性公钥=空”或一种其依赖。试图加载格式不正确的程序。

解决方案工作正常的Windows XP与普通的USB扫描仪,但是 而试图与网络扫描仪(使用ScanGear时工具发现的)在Windows 7(64位)以上遇到扫描。

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); 
     } 

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

回答

0

确保您没有将项目构建为“任何CPU”。它需要是x86。 WIA COM组件不能以64位模式运行。

+0

win应用程序与x86运行时,它运行良好....谢谢你... –

0

我遇到过这个问题,甚至更多的项目无法在X64平台上成功编译。由于无法在x64模式下调用WIA COM组件,因此最后我转向另一种方式:在单个应用程序中完成WIA代码,然后使用另一个Process从主应用程序调用此扫描应用程序。我认为这不是最好的解决方案,但至少它运作良好,哈哈。

相关问题