ZXing.NET 0.16.0 HResult=0x80070057

137 Views Asked by At

Hi I try to use Barcode Reader by ZXing.

Error:

System.ArgumentException


HResult=0x80070057
  Message=Source must be non-null.
  Source=zxing
  StackTrace:
   at ZXing.Binarizer..ctor(LuminanceSource source)
   at ZXing.Common.GlobalHistogramBinarizer..ctor(LuminanceSource source)
   at ZXing.Common.HybridBinarizer..ctor(LuminanceSource source)
   at ZXing.BarcodeReaderGeneric.<>c.<.cctor>b__40_0(LuminanceSource luminanceSource)
   at ZXing.BarcodeReaderGeneric.Decode(LuminanceSource luminanceSource)
   at ZXing.BarcodeReader.Decode(Byte[] barcodeBitmap)
   at FileApi.Controllers.ToolController.BarcodeZXingReader(QrCodeParam inputParam) in C:\Data\GitRepo\FileApi\FileApi\Controllers\ToolController.cs:line 225
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<<InvokeActionMethodAsync>g__Logged|12_1>d.MoveNext()

Code:

   Byte[] byteArray = Convert.FromBase64String(inputParam.Input);
    // Create an instance of BarcodeReader class
    var barcodeReader = new BarcodeReader();

    // Set the barcode format you want to read
    barcodeReader.Options.PossibleFormats = new List<BarcodeFormat>
    {
        BarcodeFormat.QR_CODE,
        BarcodeFormat.CODE_128,
        BarcodeFormat.EAN_13
    };
    var barcodeResult = barcodeReader.Decode(byteArray);
    if (barcodeResult != null)
        return barcodeResult;
    else return "failed read it";
1

There are 1 best solutions below

1
Jyoshna Bayyapureddy On
public string GetQRImage()
{
    string qrpath = "Your QR image path";
    LuminanceSource barcodeBitmap = new ZXing.Windows.Compatibility.BitmapLuminanceSource(new Bitmap(qrpath));
    // Create a barcode reader instance
    var barcodeReader = new BarcodeReaderGeneric();
    // Decode the barcode
    var result = barcodeReader.Decode(barcodeBitmap);
    if (result == null)
        return "No barcode found.";
    return result.Text;
}