Get Started
In this guide you will learn step-by-step how to add ID Capture to your application.
Using ID Capture at the same time as other modes (e.g. Barcode Capture or Text Capture) is not supported.
The general steps are:
- Creating a new Data Capture Context instance
- Accessing a Camera
- Configuring the Capture Settings
- Implementing a Listener to Receive Scan Results
- Setting up the Capture View and Overlay
- Starting the Capture Process
Prerequisites
Before starting with adding a capture mode, make sure that you have a valid Scandit Data Capture SDK license key and that you added the necessary dependencies. If you have not done that yet, check out this guide.
You can retrieve your Scandit Data Capture SDK license key by signing in to your account Dashboard.
Create the Data Capture Context
The first step to add capture capabilities to your application is to create a new data capture context. The context expects a valid Scandit Data Capture SDK license key during construction.
DataCaptureContext context = DataCaptureContext.ForLicenseKey("-- ENTER YOUR SCANDIT LICENSE KEY HERE --");
Add the Camera
You need to also create the Camera:
camera = Camera.GetDefaultCamera();
if (camera != null)
{
// Use the settings recommended by id capture.
camera.ApplySettingsAsync(IdCapture.RecommendedCameraSettings);
context.SetFrameSourceAsync(camera);
}
Create ID Capture Settings
Use IdCaptureSettings to configure the types of documents that you’d like to scan. Check IdDocumentType for all the available options.
Using IdDocumentType.DlViz or IdDocumentType.IdCardViz together with any MRZ document (IdDocumentType.IdCardMrz,IdDocumentType.VisaMrz, IdDocumentType.PassportMrz, IdDocumentType.SwissDlMrz) while SupportedSides.FrontAndBack is enabled is currently not supported.
IdCaptureSettings settings = new IdCaptureSettings
{
SupportedDocuments = IdDocumentType.IdCardViz | IdDocumentType.DlViz | IdDocumentType.AamvaBarcode
};
Implement the Listener
To receive scan results, implement IIdCaptureListener. A result is delivered as CapturedId. This class contains data common for all kinds of personal identification documents. For more specific information use its non-null result properties (for example CapturedId.AamvaBarcode).
public class MyListener : NSObject, IIdCaptureListener
{
public void OnIdCaptured(IdCapture mode, IdCaptureSession session, IFrameData data)
{
CapturedId capturedId = session.NewlyCapturedId;
// The recognized fields of the captured ID can vary based on the type.
if (capturedId.CapturedResultType == CapturedResultType.MrzResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.VizResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.AamvaBarcodeResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.UsUniformedServicesBarcodeResult)
{
// Handle the information extracted.
}
}
public void OnErrorEncountered(IdCapture idCapture, NSError error, IdCaptureSession session, IFrameData frameData)
{
// Implement to handle an error encountered during the capture process.
}
public void OnObservationStarted(IdCapture mode)
{ }
public void OnObservationStopped(IdCapture mode)
{ }
}
Alternatively to register IIdCaptureListener interface it is possible to subscribe to corresponding events. For example:
idCapture.IdCaptured += (object sender, IdCaptureEventArgs args) =>
{
CapturedId capturedId = args.Session.NewlyCapturedId;
// The recognized fields of the captured ID can vary based on the type.
if (capturedId.CapturedResultType == CapturedResultType.MrzResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.VizResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.AamvaBarcodeResult)
{
// Handle the information extracted.
}
else if (capturedId.CapturedResultType == CapturedResultType.UsUniformedServicesBarcodeResult)
{
// Handle the information extracted.
}
};
Create a new ID Capture mode with the chosen settings. Then register the listener:
idCapture = IdCapture.Create(context, settings);
idCapture.AddListener(new MyListener())
Use a Capture View to Visualize the Scan Process
When using the built-in camera as frame source, you will typically want to display the camera preview on the screen together with UI elements that guide the user through the capturing process. To do that, add a DataCaptureView to your view hierarchy:
DataCaptureView dataCaptureView = DataCaptureView.Create(dataCaptureContext, View.Bounds);
View.AddSubview(dataCaptureView);
Alternatively you can use a DataCaptureView from XAML in your MAUI application. For example:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:scandit="clr-namespace:Scandit.DataCapture.Core.UI.Maui;assembly=ScanditCaptureCoreMaui">
<ContentPage.Content>
<AbsoluteLayout>
<scandit:DataCaptureView
x:Name="dataCaptureView"
AbsoluteLayout.LayoutBounds="0,0,1,1"
AbsoluteLayout.LayoutFlags="All"
DataCaptureContext="{Binding DataCaptureContext}" >
</scandit:DataCaptureView>
</AbsoluteLayout>
</ContentPage.Content>
</ContentPage>
You can configure your view in the code behind class. For example:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
// Initialization of DataCaptureView happens on handler changed event.
dataCaptureView.HandlerChanged += DataCaptureViewHandlerChanged;
}
private void DataCaptureViewHandlerChanged(object? sender, EventArgs e)
{
// Your dataCaptureView configuration goes here, e.g. add overlay
}
}
For MAUI development add Scandit.DataCapture.Core.Maui NuGet package into your project.
Then create an instance of IdCaptureOverlay attached to the view:
overlay = IdCaptureOverlay.Create(idCapture, dataCaptureView);
The overlay chooses the displayed UI automatically, based on the selected IdCaptureSettings. If you prefer to show a different UI or to temporarily hide it, set the appropriate IdCaptureOverlay.IdLayout.
Turn on the Camera
Finally, turn on the camera to start scanning:
camera.SwitchToDesiredStateAsync(FrameSourceState.On);
And this is it. You can now scan documents.