Show scanner

After the initialization is completed and the scenario is set, you can start document scanning process.

Xamarin.Android

There are several options on how to open the camera activity.

#1

Use this method to open camera preview activity using the default back camera, which will pass frames for recognition and return results in the completion block when they are ready. Activity will be opened from the context which has been passed to the method:

DocumentReader.Instance().ShowScanner(ApplicationContext, this);

#2

Use this method to open camera preview activity using the specified camera, which will pass frames for recognition and return results in the completion block when they are ready. Activity will be opened from the context which has been passed to the method:

DocumentReader.Instance().ShowScanner(ApplicationContext, 0, this);

Completion callback

The current results are returned in the completion block from each camera shot with different actions (DocReaderAction enum) during the scanning process:

  • Complete - scanning process was finished

  • Process - scanning process is not finished, you can get an intermediate result from the completion block

  • Cancel - scanning process was canceled by the user

public void OnCompleted(int action, DocumentReaderResults results, string error)
{
if (action == DocReaderAction.Complete)
{
Toast.MakeText(this, "Completed", ToastLength.Long).Show();
}
else
{
// something happened before all results were ready
if (action == DocReaderAction.Cancel)
{
Toast.MakeText(this, "Scanning was cancelled", ToastLength.Long).Show();
}
else if (action == DocReaderAction.Error)
{
Toast.MakeText(this, "Error:" + error, ToastLength.Long).Show();
}
}
}

Xamarin.iOS

public partial class ViewController : UIViewController
{
// Use this code for recognize on photo from camera
partial void UseCameraButtonTouch(UIButton sender)
{
// start recognize
RGLDocReader.Shared.ShowScanner(this, ShowScannerCompleted);
}
‚Äč
void ShowScannerCompleted(RGLDocReaderAction action, RGLDocumentReaderResults result, string error)
{
switch (action)
{
case RGLDocReaderAction.Cancel:
Console.WriteLine("Cancelled by user");
break;
case RGLDocReaderAction.Complete:
Console.WriteLine("Completed");
// through all available text fields
foreach (var textField in result.TextResult.Fields)
{
var value = result.GetTextFieldValueByType(textField.FieldType, textField.Lcid);
if (value != null)
Console.WriteLine("Field type name: {0}, value: {1}", textField.FieldName, value);
}
break;
case RGLDocReaderAction.Error:
Console.WriteLine("Error string: " + error);
break;
case RGLDocReaderAction.Process:
Console.WriteLine("Scaning not finished. Result: " + result);
break;
}
}
}

The current results are returned in the completion block from each camera shot with different actions (RGLDocReaderAction enum) during the scanning process:

  • Complete - scanning process was finished

  • Process - scanning process is not finished, you can get an intermediate result from the completion block

  • Cancel - scanning process was canceled by the user