Reading QRCode with Zxing in Java

前端 未结 3 1905
春和景丽
春和景丽 2020-12-13 21:05

Some questions about using Zxing...

I write the following code to read barcode from an image:

public class BarCodeDecode 
{
    /**
     * @param arg         


        
3条回答
  •  离开以前
    2020-12-13 22:03

    This Code worked for me.

    public static List ScanForBarcodes(string path)
    {
      return ScanForBarcodes(new Bitmap(path));
    }
    
    public static List ScanForBarcodes(Bitmap bitmap)
    {
      // initialize a new Barcode reader.
      BarcodeReader reader = new BarcodeReader
      {
        TryHarder = true, // TryHarder is slower but recognizes more Barcodes
        PossibleFormats = new List // in the ZXing There is an Enum where all supported barcodeFormats were contained
        {
          BarcodeFormat.CODE_128, 
          BarcodeFormat.QR_CODE,
          //BarcodeFormat. ... ;
        }
      };
      return reader.DecodeMultiple(bitmap).Select(result => result.Text).ToList(); // return only the barcode string.
                                                                                   // If you want the full Result use: return reader.DecodeMultiple(bitmap);
    }
    

    Did you use this (ZXing.Net) Lib?

提交回复
热议问题