ZXing库条形码解码失败

时间:2018-10-04 18:12:44

标签: java barcode zxing

使用Java中的Zxing库解码TIFF文件中存在的条形码,尽管其中包含条形码,但对于少数TIFF图像不起作用。 下面的代码用于检查TIFF中的条形码:

public boolean isBarcodePresent(String tiffFile) throws IOException{
boolean isBarcodePresent = false;
BufferedImage bufferedTifImage = ImageIO.read(new File(tiffFile));

 LuminanceSource source = new  BufferedImageLuminanceSource(bufferedTifImage);

              BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

              Reader reader = new MultiFormatReader();

              Result result = null;

              try {

                     Map<DecodeHintType,Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);

            tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);

                     result = reader.decode(bitmap, tmpHintsMap);

              } catch (Exception e) {

                     log.error("Exception while reading barcode", e);

                     isBarcodePresent = false;

              }

              if (result != null && result.getText().equalsIgnoreCase("TRANSACTION")) {

                     isBarcodePresent = true;

              }
  return isBarcodePresent;

       }

此图像失败: TIFF

0 个答案:

没有答案