0
我試圖讓程序讀取QR碼,但是當我的代碼運行時,我收到一個異常javax.imageio.IIOException: Can't read input file
。該圖像位於src目錄中。可能有人請幫助我找到我的代碼的問題...無法在程序中讀取輸入文件以讀取QR碼
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();
}
}
}
最後,我可以解決這個問題。 (1)我把我的圖像放在src目錄之外。 (2)開始時,我製作了一個大尺寸的QR碼並試圖讀取它。但不能。 然後我用一個小尺寸的QR代替它,並可以閱讀。但我不知道爲什麼。 非常感謝您的幫助! – Benben 2012-04-16 11:52:50