【发布时间】:2014-07-15 13:53:51
【问题描述】:
我正在尝试使用以下代码在 Java 中扫描二维条码:
InputStream in = null;
BufferedImage bfi = null;
File[] files = new File("codes").listFiles();
for (int i = 0; i < files.length; i++) {
try {
in = new FileInputStream(files[i]);
bfi = ImageIO.read(in);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (bfi != null) {
LuminanceSource source = new BufferedImageLuminanceSource(
bfi);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
source));
Reader reader = new MultiFormatReader();
Result result = null;
Hashtable<DecodeHintType, Object> decodeHints = new Hashtable<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
try {
result = reader.decode(bitmap, decodeHints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
System.out.println("Text: " + result.getText());
} else {
System.out.println("No Buffered Image for"
+ files[i].getName());
}
}
我尝试扫描的图像类型类似于以下图像: http://www.apparategemeinschaft.de/07_s01.jpg
我主要需要扫描 pdf417。
当我简单地扫描二维条码的图片时,它就可以工作。 zxing 甚至是用来做我想做的事吗?
我应该说清楚:对于我扫描的所有 .tif 图像,我都会收到消息“没有用于...的缓冲图像”
更新:
我在类路径中添加了以下 jar: jai_imageio_linux-amd64.jar
并且没有按照 Robby 的建议更改任何代码。
还是不行。
第二次更新:
我现在明白了。 ImageIO.getReaderFileSuffixes() 现在也包含 .tiff。
新问题:我必须告诉zxing图片上有多个条形码吗?
【问题讨论】: