A lot of our customers asking us about a way to acquire images from a scanner and other imaging devices.
There are 2 ways to acquire an image in Windows:
What about WIA? In the latest version of BarCode Reader SDK, we have implemented a new WIAImageScanner class that allows us to acquire images and works on Windows XP, Vista, 7, Windows 8 for both x86 and x64 platforms.
The latest evaluation version of BarCode Reader SDK is available for download here
Registered users should download using their “secret” link instead (to get the full version)
using System; using System.IO; using System.Text; using System.Windows.Forms; using Bytescout.BarCodeReader;
// This example demonstrates camera image acquiring using Windows Image Acquisition (WIA).
// using built-in WIAImageScanner class from barCode Reader SDK
namespace BarcodeFromWebCam { static class Program { static void Main() { // create WIA scanner object WIAImageScanner wiaScanner = new WIAImageScanner(); wiaScanner.OutputFileNameTemplate = "BarCodeReader-scanned"; wiaScanner.OutputImageFormat = WiaImageFormatType.PNG; wiaScanner.ImageQuality = WiaImageBias.MaximizeQuality; wiaScanner.ImageIntent = WiaImageIntent.UnspecifiedIntent; wiaScanner.ShowDeviceSelectionDialog = true; try { // run acquire and exit if canceled or zero images if (!wiaScanner.Acquire()) return; } catch (Exception E) { string message = E.Message; if (E.InnerException != null) message = message + "rnrn" + E.InnerException.Message; MessageBox.Show("Error while acquiring images:rnrn" + message); return; } // Read barcode: Reader barcodeReader = new Reader(); FoundBarcode[] barcodes = barcodeReader.ReadFrom(wiaScanner.OutputFiles[0]); if (barcodes.Length > 0) { StringBuilder builder = new StringBuilder(); foreach (FoundBarcode barcode in barcodes) builder.AppendLine(String.Format("Found barcode with type '{0}' and value '{1}'", barcode.Type, barcode.Value)); MessageBox.Show(builder.ToString()); } else { MessageBox.Show(wiaScanner.OutputFiles[0] + "rnrnCould not find any barcode."); } } } }
Imports System.IO Imports System.Text Imports System.Windows.Forms Imports Bytescout.BarCodeReader
‘ This example demonstrates camera image acquiring using Windows Image Acquisition (WIA).
‘ using built-in WIAImageScanner class from barCode Reader SDK
NotInheritable Class Program Private Sub New() End Sub Friend Shared Sub Main() ' use WIA barcode reader scanner Dim wiaScanner As WIAImageScanner = New WIAImageScanner wiaScanner.OutputFileNameTemplate = "BarCodeReader-scanned" wiaScanner.OutputImageFormat = WiaImageFormatType.PNG wiaScanner.ImageQuality = WiaImageBias.MaximizeQuality wiaScanner.ImageIntent = WiaImageIntent.UnspecifiedIntent wiaScanner.ShowDeviceSelectionDialog = True Try ' run acquire and exit if canceled or zero images If Not wiaScanner.Acquire() Then Return End If Catch E As Exception Dim message As String = E.Message If E.InnerException IsNot Nothing Then message = message + "rnrn" + E.InnerException.Message MessageBox.Show("Error while acquiring images:rnrn" + message) Return End If End Try ' Read barcode: Dim barcodeReader As New Reader() Dim barcodes As FoundBarcode() = barcodeReader.ReadFrom(wiaScanner.OutputFiles(0)) If barcodes.Length > 0 Then Dim builder As New StringBuilder() For Each barcode As FoundBarcode In barcodes builder.AppendLine([String].Format("Found barcode with type '{0}' and value '{1}'", barcode.Type, barcode.Value)) Next MessageBox.Show(builder.ToString()) Else MessageBox.Show(wiaScanner.OutputFiles(0) + "" & Chr(13) & "" & Chr(10) & "" & Chr(13) & "" & Chr(10) & "Could not find any barcode.") End If End Sub End Class