我已经尝试解码 QR 码很多天了,并且能够解码由免费应用程序和东西生成的 QR 码。问题是当我尝试使用从相机拍摄的可能模糊的图像时,有额外的内容,以轻微的角度捕获,我无法解码它们。
注意:我不想使用意图来调用现有的条形码阅读器。
Bitmap bmap=BitmapFactory.decodeResource(getResources(),R.drawable.qrImage);
LuminanceSource source = new RGBLuminanceSource(bmap);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeMultiReader();
try{
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
Result result = reader.decode(bitmap, hints);
TextView tv= (TextView) findViewById(R.id.tv1);
tv.setText(result.getText());
}catch(Exception e)
{
e.printStackTrace();
}