OcrControl.Failed Event

 

Deprecated. The Failed Event is raised when an error occurs in The Bing Optical Character Recognition (OCR) Control, such as when no camera is available, user has denied permissions to access the camera, or the control is unable to contact the Bing OCR Service. All error messages from the control to the hosting application come through this event.

Published date: March 4, 2014

Warning

The Bing OCR Control is deprecated as of March 12, 2014

Syntax

public event EventHandler<OcrErrorEventArgs> Failed
<Ocr:OcrControl Failed="MyEventHandler(OcrErrorEventArgs e);" .../>

Example

The following code example shows how to handle the Failed event. The error handler writes text to a TextBlock named tbResult, and then either resumes video preview or cancels, depending on the error.

Note that the error handler is declared as an async method so that it can await the StartPreviewAsync() or ResetAsync() call at the end.

// Assign the event handler in the XAML page constructor.
public MainPage()
{
    this.InitializeComponent();
    OCR.Failed += OCR_ErrorOccurred;
    …
}

// Handle the event.
private async void OCR_ErrorOccurred(object sender, OcrErrorEventArgs e)
{
    // Display error message.
    tbResults.Text = e.ErrorMessage;

    // Give guidance on specific errors.
    switch (e.ErrorCode) 
    {
        case ErrorCode.CameraBusy:
            tbResults.Text += "\nClose any other applications that may be using the camera and try again.";
            break;
        case ErrorCode.CameraLowQuality:
            tbResults.Text += "\nThe rear facing camera on this device does not meet the resolution requirements for OCR.";
            break;
        case ErrorCode.CameraNotAvailable:
            tbResults.Text += "\nNo rear facing camera could be found.";
            break;
        case ErrorCode.CameraPermissionDenied:
            tbResults.Text += "\nTurn camera permissions on in your application settings.";
            break;
        case ErrorCode.NetworkUnavailable:
            tbResults.Text += "\nCheck your Internet connection and try again.";
            break;
        default:
            tbResults.Text += "\nNotify your application provider.";
            break;
    }

    // Continue or cancel, depending on the error.
    if (e.ErrorCode == ErrorCode.Success)
    {
         await OCR.StartPreviewAsync();
    }
    else
    {
        await OCR.ResetAsync();
    }
}

Requirements

Minimum Supported Client

Windows 8.1

Required Extensions

Bing OCR

Namespace

Bing.Ocr