We hope you caught yesterday's second coding session with our Developer Support Agent Matt. Here is the final part of his three-part-mini-series about the LEADTOOLS Xamarin Camera control and the Barcode SDK. At the end of this video, you will have developed a live capture barcode recognition application to read all of LEADTOOLS supported barcodes.
For this video, Matt will show you how to capture each frame from the camera and then check if a barcode has been found or not. If a barcode has been found, then a display message will appear on the devices screen.
Thanks tuning in to our first mini-series coding session. There will be more to come!
https://youtu.be/s9RJGZfBka0
For convenience, the code below is from the video, allowing you to copy and paste it to your IDE as you follow.
private static readonly BarcodeEngine barcodeEngine = new BarcodeEngine();
//setup lead
#if __IOS__
Leadtools.Converters.Assembly.Use();
#endif
Leadtools.Core.Assembly.Use();
Leadtools.Svg.Assembly.Use();
Leadtools.Camera.Xamarin.Assembly.Use();
Leadtools.Platform.RuntimePlatform = Device.RuntimePlatform;
leadCamera.CameraOptions.AutoRotateImage = true;
private void LiveCapture(object sender, EventArgs args)
{
liveCaptureLabel.Text = "Live Capture Enabled";
liveCaptureLabel.TextColor = Color.Green;
leadCamera.FrameReceived += LeadCamera_FrameReceived;
}
// Occurs for every frame delivered from the hardware device.
private void LeadCamera_FrameReceived(FrameHandlerEventArgs e)
{
var data = barcodeEngine.Reader.ReadBarcode(e.Image, LeadRect.Empty, BarcodeSymbology.Unknown);
if (e.Image != null && data.Value != null)
{
Device.BeginInvokeOnMainThread(() =>
{
DisplayAlert("Barcode Found!", $"Barcode: {data.Symbology}∖nValue: {data.Value}∖nBounds: {data.Bounds}∖nAngle: {data.RotationAngle}", "OK");
});
leadCamera.FrameReceived -= LeadCamera_FrameReceived;
liveCaptureLabel.Text = "Live Capture Disabled";
liveCaptureLabel.TextColor = Color.Red;
}
}
}