WIA (Windows Image acquire, latest version 2.0) is a collection of standard APIs for capturing images from devices in Windows, which can obtain still images from devices such as scanners, digital cameras, and manage these devices. It is both an API and DDI (Device Driver Interface). Therefore, as long as the device satisfies this specification, it can use WIA to interact directly with the application, rather than through the driver. WIA even provides a unified dialog box to get pictures.
WIA is COM-based, and there are two ways to use it:
- C + +: Using the WIA custom interface
- Other: Use Wiaal (WIA Automation Layer).
Note: Wiaal does not exist in previous versions of Windows XP SP1, so the second way is with the WIA Scripting Model.
Using WIA in. NET, we are using the second method. Next, do a simple image scanning program:
Interface
Create a new WinForm application, add a button and a picture frame, click the button to start the scanning process, and then display the image in the picture box, the application interface is as follows:
Using WIA
Visual Studio 2010 has the benefit of automating the assembly of COM components and adding a WIA COM reference to the project:
When you click OK, a WIA.Interop.dll file is added to the project reference, which you can view in the Object Browser:
Open the Scan dialog box
You can then use WIA to scan, and the steps are simple, first referencing namespaces:
using WIA;
Next, in the Click event of the button, add the following code:
ImageFile ImageFile =NULL; Commondialogclass CDC=NewWia.commondialogclass ();Try{ImageFile=CDC. Showacquireimage (WIA). Wiadevicetype.scannerdevicetype, WIA. Wiaimageintent.textintent, WIA. Wiaimagebias.maximizequality,"{00000000-0000-0000-0000-000000000000}", true, true, false);}Catch(System.Runtime.InteropServices.COMException) {ImageFile=NULL;}
WIA will automatically pop up the standard Scan dialog box for scanning operations:
Get images
After the showacquireimage is called, the scanned data is saved in the ImageFile object. The data in the ImageFile is read in the following way (the method is silly and silly ...). Very silly)
if NULL ) { imagefile.savefile (@ "c:\1.bmp"); using New FileStream (@ "c:\1.bmp", FileMode.Open, FileAccess.Read, FileShare.Read)) { = Image.fromstream (stream); } File.delete (@ "c:\1.bmp");}
The results are as follows:
Use WIA to get scanner data in C #