62,614
社区成员
发帖
与我相关
我的任务
分享
/**
* 条形码进行解析
* @param imgPath
* @return
*/
public static String decodeBarCode(String imgPath) {
BufferedImage image = null;
Result result = null;
try {
image = ImageIO.read(new File(imgPath));
if (image == null) {
throw new Exception("the decode image may be not exit.");
}
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
result = new MultiFormatReader().decode(bitmap, null); //这里报错
return result.getText();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}