DocumentScanner
Namespace: Wisej.Web.Ext.Dynamsoft
Assembly: Wisej.Web.Ext.Dynamsoft (4.1.0.0)
A Dynamsoft Document Scanner Integration.
- C#
- VB.NET
public class DocumentScanner : DSBase
Public Class DocumentScanner
Inherits DSBase
The control shows the video stream of the camera and detects the boundaries of the documents using the Dynamsoft JavaScript Document Normalizer and Camera Enhancer. Scanning starts as soon as the scanner is created in the browser, which requires ProductKey. To capture a document, call ConfirmQuadForNormalization, let the user adjust the boundary, then call NormalizeWithConfirmedQuadAsync to retrieve the normalized image.
Example:
The following example captures a document in two steps and restarts the scanning after saving it.
private void buttonCapture_Click(object sender, EventArgs e)
{
// pauses the video and lets the user adjust the document boundary.
this.documentScanner1.ConfirmQuadForNormalization();
}
private async void buttonSave_Click(object sender, EventArgs e)
{
var image = await this.documentScanner1.NormalizeWithConfirmedQuadAsync();
if (image != null)
{
this.pictureBoxDocument.Image = image;
this.documentScanner1.Reset();
}
}
Constructors
DocumentScanner()
Constructs a new instance of the DocumentScanner class.
Example:
The following example adds a document scanner to a form.
var scanner = new DocumentScanner();
scanner.ProductKey = Environment.GetEnvironmentVariable("DYNAMSOFT_DDN_KEY");
scanner.Dock = DockStyle.Fill;
this.Controls.Add(scanner);
Properties
InitScript
String: Returns the script that creates the Dynamsoft document scanner in the browser.
The value is always the script embedded in the extension (Wisej.Web.Ext.Dynamsoft.DocumentScanner.js); assigning a different script doesn't change the returned value.
ProductKey
String: Gets or sets the JS Dynamsoft Document Normalizer product key to use for the scanner.
The key is passed to the browser in the productKey field of Options and assigned to the Dynamsoft license. Changing the key recreates the scanner.
Example:
The following example reads the license key from an environment variable.
this.documentScanner1.ProductKey = Environment.GetEnvironmentVariable("DYNAMSOFT_DDN_KEY");
Methods
ConfirmQuadForNormalization()
Pauses the video stream and enters “editor mode” where the quadrilaterals in current frame are selectable and editable. Then you can select one quadrilateral that contains the content you are interested in and edit it to a desirable shape to be normalized.
Call NormalizeWithConfirmedQuadAsync to retrieve the normalized image of the selected quadrilateral.
Example:
The following example freezes the current frame when the user clicks the "Capture" button.
private void buttonCapture_Click(object sender, EventArgs e)
{
this.documentScanner1.ConfirmQuadForNormalization();
this.buttonSave.Enabled = true;
}
Dispose(disposing)
Clean up any resources being used.
| Parameter | Type | Description |
|---|---|---|
| disposing | Boolean | true if managed resources should be disposed; otherwise, false. |
NormalizeWithConfirmedQuadAsync()
Normalizes the image with the one quadrilateral which is confirmed in ConfirmQuadForNormalization.
Returns: Task<Image>. A task that returns the normalized document as a PNG Image, or null when the normalization failed.
Example:
The following example shows the normalized document and scans the next one.
private async void buttonSave_Click(object sender, EventArgs e)
{
var image = await this.documentScanner1.NormalizeWithConfirmedQuadAsync();
if (image == null)
{
AlertBox.Show("The document could not be captured.");
return;
}
this.pictureBoxDocument.Image = image;
this.documentScanner1.Reset();
}
PauseScanning()
Pauses continuous scanning but keeps the video stream.
Example:
The following example pauses the scanning while a dialog is shown.
this.documentScanner1.PauseScanning();
await new SettingsDialog().ShowDialogAsync();
this.documentScanner1.ResumeScanning();
Reset()
Restarts the scanning of document boundaries, i.e. to scan a new document after the previous one was normalized.
Stops the scanning and starts it again after half a second. When the scanner has not been created in the browser yet, the restart is delayed until it is.
Example:
The following example saves the normalized document and gets the scanner ready for the next one.
var image = await this.documentScanner1.NormalizeWithConfirmedQuadAsync();
if (image != null)
image.Save(Application.MapPath($"Documents/{Guid.NewGuid()}.png"));
this.documentScanner1.Reset();
ResumeScanning()
Resumes continuous scanning.
Example:
The following example resumes the scanning paused by a check box.
private void checkBoxPause_CheckedChanged(object sender, EventArgs e)
{
if (this.checkBoxPause.Checked)
this.documentScanner1.PauseScanning();
else
this.documentScanner1.ResumeScanning();
}
StartScanning()
Opens the camera and starts continuous scanning of incoming images.
The scanner starts scanning automatically when it is created; use this method to restart it after StopScanning.
Example:
The following example starts the scanner again when the user returns to the scanning page.
private void tabPageScan_Enter(object sender, EventArgs e)
{
this.documentScanner1.StartScanning();
}
StopScanning()
Stops continuous scanning and closes the video stream.
Example:
The following example turns off the camera when the user leaves the scanning page.
private void tabPageScan_Leave(object sender, EventArgs e)
{
this.documentScanner1.StopScanning();
}