Hi i need open scanner zxing by pressing a button, can anyone help me?
THANKS
Hi i need open scanner zxing by pressing a button, can anyone help me?
THANKS
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mohamed Azarudeen ZRank #297 · 8.5K reputationPosted May 25, 2023, 2:59 AM EDT
Add ZXing.Net.Mobile NuGet package to your Xamarin.Forms project. Right-click on your solution, select "Manage NuGet Packages," search for "ZXing.Net.Mobile," and install it.
In your Xamarin.Forms project, create a new Content Page or use an existing one where you want to include the barcode scanner.
Add the necessary namespaces at the top of your code-behind file:
using ZXing; using ZXing.Mobile;implement the click event handler for the button:
private async void OnScanButtonClicked(object sender, EventArgs e) { // Create a new instance of the MobileBarcodeScanner var scanner = new MobileBarcodeScanner(); // Set the desired barcode formats to scan scanner.TopText = "Hold camera up to barcode"; scanner.BottomText = "Barcode will be automatically scanned"; // Start scanning var result = await scanner.Scan(); // Handle the scan result if (result != null && !string.IsNullOrWhiteSpace(result.Text)) { // Barcode successfully scanned string barcodeValue = result.Text; // Do something with the barcode value // For example, display it in a label barcodeLabel.Text = barcodeValue; } }Riccardo Daria84 reputationPosted May 25, 2023, 4:01 AM EDT
Thanks, but this code is underlined:
MobileBarcodeScanner
We need something else, RIGHT?
Kip Hackman61 reputationPosted Jun 30, 2023, 10:39 AM EDT
For your use-case, to live capture barcodes from a mobile device using Xamarin, you can look into using the LEADTOOLS Barcode SDK and Xamarin Camera Control.
https://www.leadtools.com/sdk/products/barcode-pro
https://www.leadtools.com/sdk/xamarin/camera
You can leverage the CameraView class which will allow you to access a mobile device's camera. You can access the frames received from the camera using the FrameReceived event, then take that frame and detect/extract barcodes codes using the BarcodeReader class.
For an example see the code below:
private void liveCapture_Clicked(object sender, EventArgs e) { leadCamera.CameraOptions.AutoRotateImage = true; barcodeEngineInstance = new BarcodeEngine(); leadCamera.FrameReceived += LeadCamera_FrameReceived; } private void LeadCamera_FrameReceived(Leadtools.Camera.Xamarin.FrameHandlerEventArgs e) { // Frame Received Handler Code using (RasterImage image = e.Image) { BarcodeData[] dataArray = barcodeEngineInstance.Reader.ReadBarcodes(image, LeadRect.Empty, 0, null); if (dataArray != null) { leadCamera.FrameReceived -= LeadCamera_FrameReceived; StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0} barcode(s) found", dataArray.Length); sb.AppendLine(); for (int i = 0; i { DisplayAlert("Barcode(s) Found!", sb.ToString(), "OK"); }); } } }