ZXing.Net.Mobile: Unable to read large QR Codes with Xamarin

Hello All,

I’ve implemented the Zxing library into a Xamarin Forms application. And most devices struggle to decode large QR Codes (see first comment for example size). This also seems to be the case for other APIs such as Google’s Vison API. So, I can’t figure out if it is due to the library or the Xamarin framework…

However, here is my implementation:

Library versions:

  • Zxing.net.Mobile: 2.2.9
  • Xamarin-forms: 2.3.4.270 and Xamarin-forms: 2.4.0.18342

Here are the different methods I’ve implemented:

var options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
    PossibleFormats = new List<ZXing.BarcodeFormat>
    {
        ZXing.BarcodeFormat.QR_CODE
    },
    TryHarder = false,
    AutoRotate = false,
    TryInverted = false
};

var scanner = new ZXing.Mobile.MobileBarcodeScanner
{
    TopText = "Up",
    BottomText = "Down"
};



var data = await scanner.Scan(options);
 // The await never finishes
TaskCompletionSource<string> scanCompletion = new TaskCompletionSource<string>();
var options = new ZXing.Mobile.MobileBarcodeScanningOptions
{
    PossibleFormats = new List<ZXing.BarcodeFormat>
    {
        ZXing.BarcodeFormat.QR_CODE
    },
    TryHarder = false,
    AutoRotate = false,
    TryInverted = false,
};

var scanPage = new ZXingScannerPage(options);
scanPage.AutoFocus();
scanPage.Title = "QR Code";
scanPage.OnScanResult += (result) =>
{
    try
    {
        Android.Util.Log.Error("ZXING", "Barcode!!!!");
        scanCompletion.SetResult(result.Text);
    }
    catch(Exception excep)
    {
        Android.Util.Log.Error("ZXING", excep.Message);
        Android.Util.Log.Error("ZXING", excep.StackTrace);
    }
}; // This is never called

await App.Navigation.PushAsync(scanPage);
var resultQr = await scanCompletion.Task;
await DisplayAlert("QR Code", resultQr, "OK");
await App.Navigation.PopAsync();

I’m aware of #278 and the application isn’t crashing, only not scanning. The app is built without arm64-v8a.

I’ve attached the logs of when the application is running. (The NullReferenceException at the end is not important. I don’t catch anything if the user force quits the scanner with the back key. Only a test app at the moment)

ZxingScanLog.log

Thanks.

Peter.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 16 (6 by maintainers)

Commits related to this issue

Most upvoted comments

If this helps out:

LuminanceSource fast = new FastJavaByteArrayYUVLuminanceSource(fastArray, width, height, 0, 0, width, height); // _area.Left, _area.Top, _area.Width, _area.Height);
if(width > 640 && height > 440)
{
  fast = fast.crop((width - 512) / 2, (height - 512) / 2, 512, 512);
}
if (rotate)
  fast = fast.rotateCounterClockwise();
result = barcodeReader.Decode(fast);

This is how I crop to the middle 512x512 image of the raw NV21 image in Android. This is in the CameraAnalyzer class.