Dynamic .NET TWAIN is one of the excellent TWAIN-compliant SDKs for document scanning and image capture. In this tutorial, I would like to share how to create a bridge to convert .NET TWAIN C# methods to Java methods in order to help Java developers easily implement Java TWAIN scanner software.
Dynamic .NET TWAIN 5.0 has been released for a while. To help users to quickly grasp APIs, a brand-new API demo, written in WPF with C# & VB.NET, is included. In this tutorial, we would like to show the anatomy of this application. Let’s glance at the screenshot as a warm up. As you can see, the functionalities of the demo include scanner control, image loading, barcode recognition, OCR, image manipulation and processing.
How to install Dynamic .NET TWAIN 5.0?
Visit Dynamic .NET TWAIN page and get the installation package by clicking “Download” button. Follow the InstallShield Wizard step by step.
Where is the API demo?
The demo source code is located at “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\C# Samples\VS 12” and “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\VB .NET Samples\VS 12\WpfControlsDemo”. You can choose your preferred programming language, C# or VB.NET.
What does the project look like in Visual Studio?
The reference DynamicDotNetTWAIN.Wpf.dll is located at “…\Dynamsoft\Dynamic .NET TWAIN 5.0 Trial\Samples\Bin”. It will be copied to your project folder when you run the Visual Studio solution file “WpfControlsDemo.sln”. If you want to create your own project, don’t forget to add it. In this project, we have created three windows. The main window is “Window1.xaml”.
How to use the relevant APIs to implement following functions?
All implementation logics are same no matter which language you choose. Let’s illustrate with C#.
We’re proud to reveal that Dynamsoft’s Dynamic .NET TWAIN 5.0 is on its way to release soon. In addition to WinForms support, the new version will include a WPF control. You can use it in your WPF app to capture images from TWAIN scanners and UVC/WIA webcams, to edit and save images to local disks, to a server or a database. Today, I’d like to cover how, using VB.NET, you can use the Dynamic .NET TWAIN 5.0 SDK to implement barcode reading in a WPF application.
The relevant source code can be downloaded here.
1. Create a New WPF Project
First, start Visual Studio .NET, and create a new WPF project. Select Visual Basic as the type and choose WPF Application as the template.
2. Add a Reference
Right-click on the project root, and select Add Reference… from the menu. Click Browse to locate DynamicDotNetTWAIN.dll and add it.
3. Add Dynamic .NET TWAIN Component
If there is no Dynamic .NET TWAIN component available, you might need to open the toolbox. To do so, right-click on the panel and select Choose Items… Switch to the tab WPF Components and click Browse… to load DynamicDotNetTWAIN.Wpf.dll
4. Add Buttons and Textbox
Next, you’ll want to drag two buttons and one textbox from the toolbox to design a form. The buttons are used to load an image and make the detection of a barcode. And, the textbox is used to display the information decoded from barcode.
5. Code for Loading Image
Now, what you need to do is to acquire an image using the Windows standard API. Then you’ll need to load it using the Dynamic .NET TWAIN component method. Just a couple of lines of code are needed for loading an image. It’s pretty simple.
Dim filedlg As OpenFileDialog filedlg = New OpenFileDialog() filedlg.Multiselect = True Dim strFilename As String If (filedlg.ShowDialog() = DialogResult.OK) Then For Each strFilename In filedlg.FileNames DynamicDotNetTwain1.LoadImage(strFilename) Next End If
6. Code for Barcode Recognition
To decode a barcode, the path for the barcode library needs to be first be specified. Then, with one additional line of code, you’ll get results.
Set the path of barcode library
Dim strDllFolder As String strDllFolder = Application.ExecutablePath Dim pos As Integer pos = strDllFolder.LastIndexOf("\Samples\") If (pos <> -1) Then strDllFolder = strDllFolder.Substring(0, strDllFolder.IndexOf("\", pos)) + "\Bin\BarcodeResources\" End If Me.DynamicDotNetTwain1.BarcodeDllPath = strDllFolder
Get the results and display them on screen
Me.TextBox1.Text = "" Dim aryResult() As Result aryResult = Me.DynamicDotNetTwain1.ReadBarcode(Me.DynamicDotNetTwain1.CurrentImageIndexInBuffer, BarcodeFormat.All) Dim strText As StringBuilder strText = New StringBuilder() If aryResult.Length = 1 Then strText.AppendFormat(aryResult.Length & " total barcode" & ("") & " found." & Constants.vbCrLf) Else strText.AppendFormat(aryResult.Length & " total barcode" & ("s") & " found." & Constants.vbCrLf) End If For i As Integer = 0 To aryResult.Length - 1 Dim objResult As Result objResult = aryResult(i) strText.AppendFormat(" Result " & (i + 1) & Constants.vbCrLf) strText.AppendFormat(" BarcodeFormat: " & objResult.BarcodeFormat.ToString() & Constants.vbCrLf) strText.AppendFormat(" Text read: " & objResult.Text & Constants.vbCrLf) Next i Me.TextBox1.Text = strText.ToString()
I hope this brief tutorial is helpful to anyone who is looking for a .NET barcode reader SDK in VB.NET.
For further inquiries, please feel free to send me an email at kgao[at]dynamsoft.com.
Dynamic .NET TWAIN 5.0 is scheduled to be released late next month. To stay informed about all our product announcements, blog posts and more, be sure to follow us on Twitter, like us on Facebook or add us on Google+. Also, if you’d like to be amongst the first to try out the new version first, please contact support[at]dynamsoft.com.
I’m pleased to announce that Dynamic Web TWAIN 9.1 is released on August 27th, 2013.
Three exciting improvements are included in this new version:
- Added native scanning support for Mac Edition. The new property ImageCaptureDriverType allows Mac users to directly acquire images via native scan (without installing a TWAIN driver).
- Improved IE users’ experience when using a separate process for document scanning. In v9.0, IE users might need to manually allow the broker process to run. It is now automated with the enhanced security of the ActiveX edition.
- Fixed a bug where OnPostTransfer event is not triggered in some cases.
I’d love to hear any comments or suggestions about this new version. Please don’t hesitate to contact me (firstname.lastname@example.org).
You may get problems when using your application with some scanners and wonder whether it is the issue with your application or it is the device issue.
If you are using a TWAIN library and your application is supposed to work with all TWAIN compatible devices, you can use Twacker, which is a TWAIN application developed by The TWAIN Working Group. It allows you to exercise features of a TWAIN driver and to see whether the driver of your device is working fine or not.
You can download Twacker installers here:
How to use Twacker?
After the installation, you can follow the steps below to test your scanners.
- Launch Twack. Go to Windows Start menu and type Twack.
- Connect to your scanner. Click menu File-> Select Source and you will see all the available sources available on your machine.
- Test your scanner.Under File menu, check ShowUI to show the user interface of the device.
With UI hidden, you can use the Automatic Feeding setting to test ADF scanning.
Click Acquire to initiate scanning and see how your device works.
- TroubleshootIf you fail to acquire images from your scanner using Twacker, you can adjust the Message Level to see if you can get more information to pinpoint the cause of the issue.
Under Special menu, you can also check the TWAIN State transition info.
Another easy way to test your TWAIN device online
You can also test your scanner using the online demo of Dynamic Web TWAIN, which is a browser-based TWAIN SDK. You only need to install an ActiveX/Plug-in for your browser (Internet Explorer/Chrome/Firefox, Safari) and have a quick check for your scanner online.
Since Internet Explorer 7 on Windows Vista was released, Protected Mode has been introduced as a new security feature. When running in Protected Mode, Internet Explorer is a low integrity process and has limited permissions to access the user system.
When running Dynamic Web TWAIN, the scanner browser plugin for web application, on Windows Vista and above, IE Protected Mode is on by default so users consistently get issues like the following:
- ActiveX failed to access the scanners connected to the user machine
- IE crashed when ActiveX tries to acquire images from scanner due to insufficient permission
With Dynamic Web TWAIN v9.0, you can now use an independent broker process to communicate with the scanners for better compatibility and robustness.
- Avoid browser crashes caused by scanner driver problems, thus improving the robustness of the web application. The independent process will not affect the browser process.
- The independent process used for scanning has a higher permission level than the browser process. This can solve the scanning issues, such as browsers not accessing the scanner source successfully, caused by the increased security features of Windows/IE.
Read more: How to work with IE Protected Mode?
I am pleased to announce that version 9.0 is now available!
Three dramatic improvements are included in this new version:
- Do document scanning in an independent process, which greatly improves the robustness of the application.
- New license verification process. In v9.0, license key can be encrypted in licensing tool and directly embedded in scan page. So the installation & deployment process will be much easier for developers and end users.
- Support multi-thread HTTP Upload/Download, which dramatically improves upload/download performance and user experience.
For full release notes, please refer to here.
I’d love to hear any comments or suggestions about this new version. Please don’t hesitate to contact me.
In some scenarios, such as Visitor Monitoring module for a government department or Patient Tracking module for a hospital, we may need to take a snap of human faces, patient charts, user IDs and so on and then upload them to a central server. How do we implement this for a web application?
How to interact with webcams connected to a computer in browsers?
- Flash – The web application requests permission to use the camera and the user will be presented with a dialog indicating the site wishes to use the camera. After the user accepts, the application will be able to grab images from the camera.
First, you’ll need to initialize and attach the camera
- HTML5 – The biggest hurdle is only a few browser versions support HTML 5. Details >>
- 3-rd party browser plugin – Internet Explorer can interact with an imaging peripheral through an ActiveX control. Firefox and Chrome can do the same through a plugin of Netscape Plugin Application Programming Interface (NPAPI).
In this article, we are going to take a look at the 3rd option – Dynamic Webcam SDK. Unlike in the first 2 options where a developer needs to deal with camera initialization, an image capturing, editing encoding and uploading separately, everything is encapsulated in Dynamic Webcam SDK.
Introduction to the Webcam API
Dynamic Webcam SDK is a browser plugin which enables users to acquire images from a webcam, edit and then upload/save them to a database, web server or local disk. Also, it can capture a live video stream into a container and grab a snapshot to be exported to a file/binary. The plugin works with all webcams that are compatible with Windows Image Acquisition (WIA) and USB video device class (UVC).
Two editions are provided for different browsers: ActiveX Edition for IE and Plugin Edition for other browsers on Windows OS.
|Client Side||Server Side|
|ActiveX Edition – x86 x64
Plugin Edition – on Windows
|IIS, Tomcat, Apache and more|
Here you can see a working application:
1. Initialize Dynamic Webcam SDK
Firstly, copy DynamicWebcam.cab to the web server. There are 32-bit and 64-bit CAB files. Choose the proper one according to the needs. The trial and full versions of Dynamic Webcam use different class-ids.
DynamicWebcam.cab can be found in the installation folder of Dynamic Webcam SDK.
For the TRIAL version of Dynamic Webcam, insert the following code in your JS code:
<object classid="clsid:A65BC1E1-B2CE-4251-A0CB-721AC7E02B52" id="DynamicWebcam1" width="143" height="156" CodeBase = "DynamicWebcam.cab#version=8,0"> </object>
Plug-in edition can be used in Gecko-based browsers including Firefox, Chrome, Safari & Opera on PC. Please copy DynamicWebcam.msi to the web server.