可以在Android中自定义ZXing来处理保存多个二维码而无需重新加载相机吗?
我已经成功集成ZXing QR Scanner。我正在做的是在用户完成扫描 1 个 QR 码后重复扫描。我面临的问题是,如果我通过这种方法多次扫描二维码,ZXing 重新加载相机的速度非常慢。还有更好的方法吗?我正在考虑保存所有扫描结果而不重新加载相机(关闭和打开)。
我只扫描我自己定制的二维码,因此不需要处理其他格式。
扫描
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
检索
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
//..
//Repeat scan for next QR code
Intent i = new Intent("com.google.zxing.client.android.SCAN");
i.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(i, 0);
}
else {
// Handle cancel
//...
}
}
I have successfully integrated ZXing QR Scanner. What I am doing is to repeat the scan once the user has finished scanning 1 QR code. The problem I faced is that ZXing is extremely slow in reloading of camera if I do multiple scanning of QR codes through this method. Are there better ways? I am looking at saving all the scans without the camera reloading (turning off and on).
I am only scanning my own customised QR codes so I do not need to handle other formats.
Scanning
Intent intent = new Intent("com.google.zxing.client.android.SCAN");
intent.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(intent, 0);
Retrieving
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (requestCode == 0) {
if (resultCode == RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String format = intent.getStringExtra("SCAN_RESULT_FORMAT");
// Handle successful scan
//..
//Repeat scan for next QR code
Intent i = new Intent("com.google.zxing.client.android.SCAN");
i.putExtra("SCAN_MODE", "QR_CODE_MODE");
startActivityForResult(i, 0);
}
else {
// Handle cancel
//...
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ZXing 重新加载任何内容的速度并不慢——这是相机驱动程序初始化相机所花费的时间。没有太多办法解决这个问题。但是,如果您愿意,您可以简单地不关闭相机并保持预览运行。
查看应用程序的批量扫描模式 - 它已经可以在不停止的情况下进行扫描以显示结果。
ZXing is not slow at reloading anything -- this is time taken by the camera driver to init the camera. There's not much way around that. But, you can simply not close the camera and keep the preview running if you want.
See the app's bulk scan mode -- it already can scan without stopping to show the results.