Windows Presentation Foundation (WPF), introduced with .NET
framework 3.0, is an API for creating graphical user interfaces for the Windows
platform. Although WinForm is a mature proven technology, more and more
developers turn to WPF for its better handling of Graphics and animation.
Compared to the traditional forms applications, WPF allows you to customize
controls in a most efficient and flexible way.
Dynamsoft’s Dynamic .NET
TWAIN is a .NET component that can be embedded into a WPF application. You
can use the component in different stages of document processing, from image
scanning, editing to the final image storage. In this article, I’ll provide the
integration steps and the image-processing functions/features that can be
Here I assume you’ve already installed
Dynamic .NET TWAIN on your development machine.
Visual Studio and create a WPF application.
to Solution Explorer -> References, add “Dynamic .NET TWAIN” and any other
.NET references that you can’t find in the Explorer as shown in the below code
Initialize Dynamic .NET TWAIN component.
Create a grid to hold the component. Change the .xaml file like this:
Title="Acquire Image" Height="600" Width="500" Loaded="Window_Loaded">
<Grid Name="grid1" Height="400" Width="300">
<WindowsFormsHost ></WindowsFormsHost> </Grid>
In the .xaml.cs file, add the namespace for Dynamic .NET TWAIN, and then
insert the following lines of code in the event
Window_Loaded to initialize the
public partial class MainWindow : Window
DynamicDotNetTwain objDynamicDotNetTwain = null;
private void Window_Loaded(object sender, RoutedEventArgs e)
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
objDynamicDotNetTwain = new DynamicDotNetTwain();
objDynamicDotNetTwain.Width = 200;
objDynamicDotNetTwain.Height = 300;
host.Child = objDynamicDotNetTwain;
to the .xaml file to add the required buttons. In this sample, you can see that
two buttons have been added:
btnAcquire. More functions can be
added according to your requirements.
Title="MainWindow" Height="600" Width="500" Loaded="Window_Loaded">
<Grid Name="grid1" Height="400" Width="300">
<Button Height="23" HorizontalAlignment="Left" Margin="0,0,0,-37" Name="btnSelect" VerticalAlignment="Bottom" Width="88" Click="btnSelect_Click">Select Source
<Button Height="23" Margin="103,0,148,-37" Name="btnAcquire" VerticalAlignment="Bottom" Click="btnAcquire_Click">Acquire</Button>
Scanning. After you add the buttons, you can insert the source code to
implement the planned functions.
btnSelect is going to show all the
available sources of your devices, including attached/remote scanners, webcams,
etc. The latest version of Dynamic .NET TWAIN (v4.1) is compatible with all
TWAIN, WIA and UVC compatible devices.
private void btnSelect_Click(object sender, RoutedEventArgs e)
btnAcquire, you can capture images and documents from the selected
private void btnAcquire_Click(object sender, RoutedEventArgs e)
objDynamicDotNetTwain.IfDisableSourceAfterAcquire = true;
By default, most of the devices (including TWAIN2 FreeImage
Software Scanner 2.1 shown in the screenshot) will prompt you the user
interface of the source when clicking on "Acquire". Through the user interface,
users can adjust the properties of the images, for instance, single/duplex
scan, color mode, resolution, page size, brightness, contrast, etc. This gives
your customers the most flexibility during the document scanning process.
However, some businesses and organizations, such as the banks and governments
planning to scan user IDs, may want to standardize the page size, resolution
and/or other image properties. This is also supported by Dynamic .NET TWAIN. A
rich set of properties are provided by the control that enables you to hard
code the properties. Here is an example:
Other Features Supported by
Dynamic .NET TWAIN
Besides image scanning, you can add many more functions to
your WPF application with the help of Dynamic .NET TWAIN.
Edit the scanned the images. Rotate, crop, flip and/or mirror the
images to better fit your needs.
Zoom in/out the images.
Upload the scanned images to the local folder, FTP site, web
server or database.
Sample Code Download
If you are interested in the WPF sample, you can download
the source code at:
If you’d like to learn more about Dynamic .NET TWAIN, the
30-day free trial is available for you.
.NET TWAIN 30-day Free Trial Download
demos of Dynamic .NET TWAIN
If you have any questions, you
can contact our support team at firstname.lastname@example.org.