我正在尝试使程序读取 QR 码,但是当我的代码运行时出现异常javax.imageio.IIOException: Can't read input file
。该图像位于src目录中。有人可以帮我在我的代码中找到问题...
public class BarcodeSample {
public static void main(String[] args) {
Reader reader = new MultiFormatReader();
try {
BufferedImage image = ImageIO.read(new File("src/img.png"));
LuminanceSource source = new BufferedImageLuminanceSource(image);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
Result result = reader.decode(bitmap);
BarcodeFormat format = result.getBarcodeFormat();
String text = result.getText();
ResultPoint[] points = result.getResultPoints();
for (int i=0; i < points.length; i++) {
System.out.println(" Point[" + i + "] = " + points[i]);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}