Question

I am working on an application, where my app need to get input from the scanner in an image format.

This is a wpf application, a scanner is connected to the system, user put the document in scanner and print the button in the application to scan the document and then the application have to save the scanned document as image in system.

I don't want to use any paid component, I believe there must be some inbuilt way to read input from the ports.

Was it helpful?

Solution

Where I work, we wrote a custom wrapper around Windows Image Acquisition. Here's a really simple example that should capture it from the scanner the user selects.

 //Reference "Windows Image Acquisition Library v2.0" on the COM tab.

private void Button1_Click(object sender, EventArgs e)
{
    var dialog = new WIA.CommonDialog();
    var file = dialog.ShowAcquireImage(WIA.WiaDeviceType.ScannerDeviceType);
    file.SaveFile("C:\Temp\WIA." + file.FileExtension);
}

If you want to do it without displaying any dialogs, here's an awesome article with some code neatly organized in static functions of a class called WIAScanner: http://miljenkobarbir.com/using-a-scanner-without-dialogs-in-net/

To use the code from the article, assuming you have one scanner and want to use just that one, or you only want to use the first scanner on the system, you could do:

private void Button1_Click(object sender, EventArgs e)
{
    var scannerIds = WIAScanner.GetDevices();

    if(scannerIds.Count > 0) {
        var images = WIAScanner.Scan(scannerIds[0]);

        //Process the images here.
    }
}

I hope this helps.

OTHER TIPS

You acctually have a few options:

1) TWAIN

which is an API that "regulates communication between software and digital imaging devices" and runs under LGPL license, see Wikipedia see Homepage

2) Windows Imaging Acquisition

which is proprietary with Microsoft. "The WIA platform enables imaging/graphics applications to interact with imaging hardware and standardizes the interaction between different applications and scanners."

see Wikipedia see Homepage

3) Image and Scanner Interface Specification (ISIS)

which provides a full SDK for .NET applications, so probably the most helpful one to you, but is paid solution, see Wikipedia see Homepage

4) Do it on your own

If you want to create a communication layer on your very own you have to ensure at least that the device has valid USB drivers. To access any hardware you will have to introduce unmanaged code (i.e. c++) since most of these device drivers provide c++ APIs, that means create a library for basic IO operations and then create a c# wrapper for your application.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top