Google 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();
    }

}

 

 

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值