Google Zxing 只扫描二维码或者只扫描条形码
zxing
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
项目地址:https://gitcode.com/gh_mirrors/zx/zxing
免费下载资源
·
Google Zxing怎样实现扫描二维码、条形码,具体参考我
这里主要说一下,怎样选择不同的模式。
Zxing 默认支持扫描二维码、条形码两种功能,但是因为项目要求,禁止扫描二维码。那么怎样禁止扫描二维码呢?
修改源代码里面的DecodeThread.java文件即可。
注释掉decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS); 这句代码
源代码如下:
package com.jingu.app.zxing.decoding;
import java.util.Hashtable;
import java.util.Vector;
import java.util.concurrent.CountDownLatch;
import android.os.Handler;
import android.os.Looper;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.ResultPointCallback;
import com.jingu.app.main.activity.MipcaActivityCapture;
/**
* This thread does all the heavy lifting of decoding the images. �����߳�
*/
final class DecodeThread extends Thread
{
public static final String BARCODE_BITMAP = "barcode_bitmap";
private final MipcaActivityCapture activity;
private final Hashtable<DecodeHintType, Object> hints;
private Handler handler;
private final CountDownLatch handlerInitLatch;
DecodeThread(MipcaActivityCapture activity, Vector<BarcodeFormat> decodeFormats, String characterSet,
ResultPointCallback resultPointCallback)
{
this.activity = activity;
handlerInitLatch = new CountDownLatch(1);
hints = new Hashtable<DecodeHintType, Object>;<pre name="code" class="java"> // 这里选择不同的模式,ONE_D_FORMATS是条形码、QR_CODE_FORMATS是二维码,<span style="font-family: Arial, Helvetica, sans-serif;">根据需要进行注释。</span>
if (decodeFormats == null || decodeFormats.isEmpty())
{
decodeFormats = new Vector<BarcodeFormat>();
decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
// <span style="color:#ff0000;">decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);</span>
decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
}
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
if (characterSet != null)
{
hints.put(DecodeHintType.CHARACTER_SET, characterSet);
}
hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
}
Handler getHandler()
{
try
{
handlerInitLatch.await();
}
catch (InterruptedException ie)
{
// continue?
}
return handler;
}
@Override
public void run()
{
Looper.prepare();
handler = new DecodeHandler(activity, hints);
handlerInitLatch.countDown();
Looper.loop();
}
}
GitHub 加速计划 / zx / zxing
32.53 K
9.31 K
下载
ZXing ("Zebra Crossing") barcode scanning library for Java, Android
最近提交(Master分支:23 天前 )
8944e607
1 个月前
6ea3726b
Bumps `spring.version` from 6.1.5 to 6.1.8.
Updates `org.springframework:spring-test` from 6.1.5 to 6.1.8
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.5...v6.1.8)
Updates `org.springframework:spring-web` from 6.1.5 to 6.1.8
- [Release notes](https://github.com/spring-projects/spring-framework/releases)
- [Commits](https://github.com/spring-projects/spring-framework/compare/v6.1.5...v6.1.8)
---
updated-dependencies:
- dependency-name: org.springframework:spring-test
dependency-type: direct:development
update-type: version-update:semver-patch
- dependency-name: org.springframework:spring-web
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sean Owen <srowen@gmail.com> 2 个月前
更多推荐
已为社区贡献1条内容
所有评论(0)