Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using C#/WIA version 2.0 on Vista to Scan

Tags:

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.

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.

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.

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

like image 793
J Wynia Avatar asked Aug 12 '08 15:08

J Wynia


People also ask

What is using () in C#?

The using statement causes the object itself to go out of scope as soon as Dispose is called. Within the using block, the object is read-only and can't be modified or reassigned. A variable declared with a using declaration is read-only.

How do I start learning C?

Get started with C. Official C documentation - Might be hard to follow and understand for beginners. Visit official C Programming documentation. Write a lot of C programming code - The only way you can learn programming is by writing a lot of code.

Is C hard to learn?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

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;"

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 WIA does contain some more info on how to do it for multiple pages, I think (I'm yet to go further than that myself)

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

like image 163
Paul Jenkins Avatar answered Oct 20 '22 18:10

Paul Jenkins


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?

like image 44
gideon Avatar answered Oct 20 '22 18:10

gideon