Xamarin Camera Control Tutorial: Develop a Live Capture Barcode Reader, Part 3

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!

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;
		}
	}
}
This entry was posted in Video Tutorials and tagged , , , . Bookmark the permalink.

2 Responses to Xamarin Camera Control Tutorial: Develop a Live Capture Barcode Reader, Part 3

  1. hamza oubouzid says:

    Hi, I hope you’re doing well. I need a library that can scan barcodes and extract text from tickets, including details like the price and name of products. Is there any library that can accomplish this?

    • Hi Hamza,
      Thank you for your question. The LEADTOOLS toolkit is a worldclass library for extracting text and barcode data from images, as well as image processing tools to clean up any messy scans.

      Please try the toolkit out for yourself with a free 60 day evaluation.

      The download comes with demos and source code examples of barcode and character recognition to make your development process as easy as possible.

      If you have any questions please reach out to our support team through our live chat or email at support@leadtools.com.

Leave a Reply

Your email address will not be published. Required fields are marked *