使用 WIA 自动化扫描多页

发布于 10-18 10:42 字数 1664 浏览 4 评论 0原文

我正在使用 WIA Automation,并且一次很难扫描多个页面。谁能给我一些关于如何实现这一目标的提示?以下是我用来扫描文档/图像的代码示例:

public static byte[] ScanImage(int colourType, string formatId, int dpi)
    {
      _dialog = new CommonDialogClass();
      _scanner = _dialog.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false);     

  foreach (Property item in _scanner.Items[1].Properties)
  {
    switch (item.PropertyID)
    {
      case 6146: //4 is Black-white,gray is 2, colour 1   
        SetProperty(item, colourType);
        break;
      case 6147: //dots per inch/horizontal    
        SetProperty(item, dpi);
        break;
      case 6148: //dots per inch/vertical          
        SetProperty(item, dpi);
        break;
      case 6149: //x point where to start scan   
        SetProperty(item, 0);
        break;
      case 6150: //y-point where to start scan  
        SetProperty(item, 0);
        break;
      case 6151: //horizontal extent        
        SetProperty(item, (int)(8.5 * 100));
        break;
      case 6152: //vertical extent             
        SetProperty(item, 11 * 100);
        break;
    }
  }

  try
  {
    TempPath = System.IO.Path.GetTempPath() + "temp" + DateTime.Now.Ticks;

    ScannedImage = (ImageFile)_scanner.Items[1].Transfer(formatId);
    //System.IO.File.Delete(TempPath);
    ScannedImage.SaveFile(TempPath);

    //Convert image to binary
    Vector vector = ScannedImage.FileData;
    byte[] imgBin = (byte[])vector.get_BinaryData();
    ScannedImageBinary = (byte[])vector.get_BinaryData();

    //ImageFromFile = Image.FromFile(TempPath);
  }
  catch (Exception ex)
  { }

  return ScannedImageBinary;
}

I'm playing around with WIA Automation and I`m struggling to scan more than page at a time. Can anyone give me some hints on how to achieve this? Below is a sample of code I use to scan a document/image:

public static byte[] ScanImage(int colourType, string formatId, int dpi)
    {
      _dialog = new CommonDialogClass();
      _scanner = _dialog.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, false, false);     

  foreach (Property item in _scanner.Items[1].Properties)
  {
    switch (item.PropertyID)
    {
      case 6146: //4 is Black-white,gray is 2, colour 1   
        SetProperty(item, colourType);
        break;
      case 6147: //dots per inch/horizontal    
        SetProperty(item, dpi);
        break;
      case 6148: //dots per inch/vertical          
        SetProperty(item, dpi);
        break;
      case 6149: //x point where to start scan   
        SetProperty(item, 0);
        break;
      case 6150: //y-point where to start scan  
        SetProperty(item, 0);
        break;
      case 6151: //horizontal extent        
        SetProperty(item, (int)(8.5 * 100));
        break;
      case 6152: //vertical extent             
        SetProperty(item, 11 * 100);
        break;
    }
  }

  try
  {
    TempPath = System.IO.Path.GetTempPath() + "temp" + DateTime.Now.Ticks;

    ScannedImage = (ImageFile)_scanner.Items[1].Transfer(formatId);
    //System.IO.File.Delete(TempPath);
    ScannedImage.SaveFile(TempPath);

    //Convert image to binary
    Vector vector = ScannedImage.FileData;
    byte[] imgBin = (byte[])vector.get_BinaryData();
    ScannedImageBinary = (byte[])vector.get_BinaryData();

    //ImageFromFile = Image.FromFile(TempPath);
  }
  catch (Exception ex)
  { }

  return ScannedImageBinary;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事↓在人2024-10-25 10:42:56

所以这看起来就像你在谈论 C#。

请参阅此答案:使用 C#/WIA Vista 上的 2.0 版扫描

我编写了一个小型库,用于在 ADF 扫描仪上扫描多个文档:
http://adfwia.codeplex.com/

So it seems like your talking C#.

See this answer : Using C#/WIA version 2.0 on Vista to Scan

I wrote a small library for scanning multiple documents on an ADF scanner:
http://adfwia.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文