在 Vista 上使用 C#/WIA 2.0 版进行扫描

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-07-31 17:21:15  来源:igfitidea点击:

Using C#/WIA version 2.0 on Vista to Scan

提问by J Wynia

I want to implement a paperless filing system and was looking to use WIA with C# for the image acquisition. There are quite a few sample projects on CodeProject, etc. However, after downloading every one of them that I can find, I have run into a problem.

我想实现一个无纸化归档系统,并希望使用 WIA 和 C# 进行图像采集。CodeProject 上有很多示例项目,等等。但是,在下载了我能找到的每一个之后,我遇到了一个问题。

In each and every one of them, the reference to WIALib is broken. When I go to add "Microsoft Windows Image Acquisition" as a reference, the only version available on my development workstation (also the machine that will run this) is 2.0.

在每一个中,对 WIALib 的引用都被破坏了。当我添加“Microsoft Windows Image Acquisition”作为参考时,我的开发工作站(也是将运行它的机器)上唯一可用的版本是 2.0。

Unfortunately, every one of these sample projects appear to have been coded against 1.x. The reference goes in as "WIA" instead of "WIALib". I took a shot, just changing the namespace import, but clearly the API is drastically different.

不幸的是,这些示例项目中的每一个似乎都是针对 1.x 编码的。引用以“WIA”而不是“WIALib”的形式出现。我拍了一张,只是改变了命名空间导入,但显然 API 完全不同。

Is there any information on either implementing v2.0 or on upgrading one of these existing sample projects out there?

是否有关于实施 v2.0 或升级这些现有示例项目之一的任何信息?

采纳答案by Paul Jenkins

To access WIA, you'll need to add a reference to the COM library, "Microsoft Windows Image Acquisition Library v2.0" (wiaaut.dll). add a "using WIA;"

要访问 WIA,您需要添加对 COM 库“Microsoft Windows Image Acquisition Library v2.0”(wiaaut.dll) 的引用。添加“使用 WIA”;

const string wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}";
CommonDialogClass wiaDiag = new CommonDialogClass();
WIA.ImageFile wiaImage = null;

wiaImage = wiaDiag.ShowAcquireImage(
        WiaDeviceType.UnspecifiedDeviceType, 
        WiaImageIntent.GrayscaleIntent, 
        WiaImageBias.MaximizeQuality, 
        wiaFormatJPEG, true, true, false);

WIA.Vector vector = wiaImage.FileData;

(System.Drawing)

(系统图)

Image i = Image.FromStream(new MemoryStream((byte[])vector.get_BinaryData()));
i.Save(filename)

Thats a basic way, works with my flatbed/doc feeder. If you need more than one document/page at a time though, there is probably a better way to do it (from what I could see, this only handles one image at a time, although I'm not entirely sure). While it is a WIA v1 doc, Scott Hanselman's Coding4Fun article on WIAdoes contain some more info on how to do it for multiple pages, I think (I'm yet to go further than that myself)

这是一种基本方式,适用于我的平板/文档进纸器。但是,如果您一次需要多个文档/页面,那么可能有更好的方法来做到这一点(从我所见,这一次只能处理一个图像,尽管我不完全确定)。虽然它是 WIA v1 文档,但 Scott Hanselman关于 WIACoding4Fun 文章确实包含更多有关如何为多个页面执行此操作的信息,我认为(我自己还没有走得更远)

If its for a paperless office system, you might want also check out MODI (Office Document Imaging) to do all the OCR for you.

如果它用于无纸化办公系统,您可能还需要查看 MODI(Office Document Imaging)来为您完成所有 OCR。

回答by J Wynia

It doesn't needto be WIA. I was mostly looking at the WIA setup because it offers the same basic interface for different scanners. I've got 3 scanners on this machine and the TWAIN drivers/software for all of them suck (like blocking the screen during scanning).

不需要是 WIA。我主要关注 WIA 设置,因为它为不同的扫描仪提供了相同的基本界面。我在这台机器上有 3 台扫描仪,它们的 TWAIN 驱动程序/软件都很糟糕(比如在扫描过程中挡住了屏幕)。

For document management, I'm really looking for simple 200dpi grayscale scans, so most of the stuff in the TWAIN drivers is overkill.

对于文档管理,我真的在寻找简单的 200dpi 灰度扫描,所以 TWAIN 驱动程序中的大部分内容都是多余的。

That said, asking here was part of my last attempt to figure out how to do it in WIA before moving on to TWAIN.

也就是说,在这里询问是我在继续使用 TWAIN 之前最后一次尝试弄清楚如何在 WIA 中做到这一点的一部分。

回答by Paul Jenkins

Another note: You have to download the WIA 2.0 dll from Microsoft.com and then browse to the dll and add it to your project.

另一个注意事项:您必须从 Microsoft.com 下载 WIA 2.0 dll,然后浏览到该 dll 并将其添加到您的项目中。

回答by gideon

Heres how to target WIA 1.0 also so you can ship your app to Windows Xp. Something I was desperately looking for!! How to develop using WIA 1 under Vista?

此处还介绍了如何以 WIA 1.0 为目标,以便您可以将您的应用程序发送到 Windows Xp。我正在拼命寻找的东西!! Vista下如何使用WIA 1进行开发?

回答by gideon

Update: I'm adding this separately since its a different answer (a year later). I learnt XP has WIA 1.0 and Vista onward has WIA2.0. You can however install WIA 2.0 for Windows XP Sp1+ from here.

更新:我单独添加它,因为它是一个不同的答案(一年后)。我了解到 XP 有 WIA 1.0,Vista 以后有 WIA2.0。但是,您可以从此处安装适用于 Windows XP Sp1+ 的 WIA 2.0 。

I then also made a small library with code I found somewhere on the interweb here, it also has the ability to scan multiple pages: http://adfwia.codeplex.com/

然后我还用我在互联网上某处找到的代码制作了一个小型图书馆,它也具有扫描多个页面的能力:http://adfwia.codeplex.com/