我目前正在开发一种扫描仪,可以读取一张图像中的多个QR码。我设法读取图像中的QR码,但它给了我不一致的结果。假设图像中有4个QR码,有时我可以读取2个,有时3个或仅1个。与原始扫描仪(ZXing扫描仪)不同,它可以快速解码。在我的情况下,我必须确保有足够的光线,图像不会模糊解码。
我正在使用QRCodeMultiReader
解码图像。目前正在使用ZXing
Library来创建应用程序。
以下是我的代码片段:
public void onPictureTaken(byte[] data, Camera camera) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inMutable = true;
Bitmap bitmap = BitmapFactory
.decodeByteArray(data, 0, data.length, opt);
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
LuminanceSource source = new RGBLuminanceSource(bitmap);
QRCodeMultiReader multiReader = new QRCodeMultiReader();
Result[] results = multiReader.decodeMultiple(new BinaryBitmap(
new HybridBinarizer(source)), hints);
}
您好请检查Zxing条码扫描器应用程序,它在“设置扫描批量条形码”中有选项,因此您启用它并检查它您可以从一个或多个图像一次读取多个QR码,并检查Zxing库的源代码已知详细信息。
我创建了一个相机的应用程序,我使用intent
作为默认相机应用程序与每个Andriod操作系统,并且通常他们更好地优化该设备,而不是编写一个通用的相机应用程序,它将针对您的手机进行优化...所以对于相机更好地使用intent
。
为了从单个图像中提取多个QR,我尝试了下面的代码。 但结果并不一致,有时候我得到1或2或3的时间没有....这不是完美的解决方案
if(photo == null)
return;
Bitmap ScaledQr = null;
ScaledQr = Bitmap.createScaledBitmap(photo, 640,480, false);
BinaryBitmap Qr = BitMap2BinayBitmap(ScaledQr);
Result [] kpResultMulti = null;
Result kpResultSingle = null;
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, true);
//hints.put(DecodeHintType.PURE_BARCODE, true);
try {
kpResultMulti = kpReaderArr.decodeMultiple(Qr,hints);
} catch (NotFoundException e) {
// TODO Auto-generated catch block
msbox("Exception","NotFoundException");
e.printStackTrace();
}
if(kpResultMulti != null){
msbox("Total Result" ,kpResultMulti.length +"");// + photo.getWidth() + "Height=" + photo.getHeight());
for(Result kp : kpResultMulti)
{
msbox("Results",kp.getText());
}
}