請教個問題:一張圖片當中在不固定位置包含有條形碼,怎麼讀取條形碼出來呢?怎麼讀取一張圖片中的多個條形碼?用zxing讀取圖片當中的條形碼,報錯com.google.zxing.NotFoundException。有大神知道的嗎?謝謝
參考
zxing二維碼掃描的流程簡析(Android版)
Java Code Examples for com.google.zxing.DecodeHintType
Reading QRCode with Zxing in Java
設置一下TryHarder和PossibleFormats看一下
public static List<string> ScanForBarcodes(string path)
{
return ScanForBarcodes(new Bitmap(path));
}
public static List<string> ScanForBarcodes(Bitmap bitmap)
{
// initialize a new Barcode reader.
BarcodeReader reader = new BarcodeReader
{
TryHarder = true, // TryHarder is slower but recognizes more Barcodes
PossibleFormats = new List<BarcodeFormat> // 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);
}