1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 条形码 二维码扫一扫和生成二维码采用ZXing3.0开源库在android studio中实现

条形码 二维码扫一扫和生成二维码采用ZXing3.0开源库在android studio中实现

时间:2020-11-27 04:07:13

相关推荐

条形码 二维码扫一扫和生成二维码采用ZXing3.0开源库在android studio中实现

补充说明:识别文件中的条形码-zxing

/**

* 根据图片路径解析图片中的条形码,返回Result对象

*

* @param path

* @return

*/

protected Result scanningImage(String path) {

if (TextUtils.isEmpty(path)) {

return null;

}

// DecodeHintType 和EncodeHintType

Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();

hints.put(DecodeHintType.CHARACTER_SET, "utf-8"); //

BitmapFactory.Options options = new BitmapFactory.Options();

options.inJustDecodeBounds = true; // 先获取原大小

scanBitmap = BitmapFactory.decodeFile(path, options);

options.inJustDecodeBounds = false; // 获取新的大小

int sampleSize = (int) (options.outHeight / (float) 200);

if (sampleSize <= 0)

sampleSize = 1;

options.inSampleSize = sampleSize;

scanBitmap = BitmapFactory.decodeFile(path, options);

RGBLuminanceSource source = new RGBLuminanceSource(scanBitmap);

BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));

//仅能识别二维码

// QRCodeReader reader = new QRCodeReader();

MultiFormatReader multiFormatReader = new MultiFormatReader();

try {

return multiFormatReader.decode(bitmap1, hints);

} catch (NotFoundException e) {

e.printStackTrace();

}

return null;

}

在识别过程主要使用了MultiFormatReader类,它可以同时解析一维/二维的条码,而QRCodeReader类仅能识别二维码。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。