我正在使用Java zxing库使用网络摄像头扫描阿兹台克代码。不幸的是,每次尝试扫描我的Aztec时,我都会收到FormatException。看起来它检测到代码,然后出了点问题-抛出NotFoundException,直到我将Aztec放在网络摄像头前。代码:
public static String readQRCode(BufferedImage image) {
BinaryBitmap bitmap = null;
Result result = null;
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));
Map<DecodeHintType,Object> tmpHintsMap = new EnumMap<DecodeHintType, Object>(DecodeHintType.class);
tmpHintsMap.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
tmpHintsMap.put(DecodeHintType.PURE_BARCODE, Boolean.FALSE);
tmpHintsMap.put(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.AZTEC);
if (bitmap == null)
return null;
QRCodeReader reader = new QRCodeReader();
try {
result = reader.decode(bitmap, tmpHintsMap);
return result.getText();
} catch (NotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ChecksumException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
我尝试了不同的阿兹台克人,结果总是一样。图片尺寸为640x480。你们有什么主意吗?预先感谢。