我想使用XZing扫描ISBN(EAN13)。这是我的功能:
private String readBarcode(String fileName) {
File file = new File(fileName);
BufferedImage image = null;
BinaryBitmap bitmap = null;
Result result = null;
try {
image = ImageIO.read(file);
int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth());
RGBLuminanceSource source = new RGBLuminanceSource(image.getWidth(), image.getHeight(), pixels);
bitmap = new BinaryBitmap(new HybridBinarizer(source));
} catch (IOException e) {
e.printStackTrace();
}
if (bitmap == null) {
return null;
}
EAN13Reader reader = new EAN13Reader();
try {
result = reader.decode(bitmap);
System.out.println("Decoded image successfully, result was : '" + result.getText() + "'");
return result.getText();
} catch (FormatException | NotFoundException e) {
e.printStackTrace();
}
return null;
}
我试图多次扫描下面的图像: ISBN
但我只收到NotFound异常。我忘了什么吗?