酒吧code / Qr的code阅读器为Android [英] Barcode/Qr Code Reader for Android

查看:133
本文介绍了酒吧code / Qr的code阅读器为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个QR code /酒吧code在我的应用程序的读者。我想知道什么是最轻量级的解决方案来做到这一点(从zxing无视意图积分)。

i would like to implement a QR Code/Barcode reader within my application. I would like to know what is the most lightweight solution to do this (disregarding intent integrator from zxing).

推荐答案

我用zxing打造成了我的应用程序。您将需要一个位编码。首先包括core.jar添加,其在核心/ core.jar添加,在您的构建路径,然后去他们的客户,其在机器人/..../ com.google.zxing,并得到他们的code(这是不推荐使用的开发者,因为你的拷贝和粘贴)最后,添加这个code:

I used zxing to build into my application. You will need a bit of coding. First include core.jar , its at core/core.jar,in your build path, then go to their client ,its at android/..../com.google.zxing, and get their code(This is not recommended by the devs, because your copy and pasting.) last, Add this code:

   package com.wtsang02.activities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.ChecksumException;
import com.google.zxing.FormatException;
import com.google.zxing.LuminanceSource;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Reader;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.google.zxing.common.HybridBinarizer;


public class QRDecoder extends Activity implements OnClickListener {

    private String text;
    private Button webbutton;
    private Bitmap bmp;
    private ImageView ivPicture;
    private TextView textv;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mysales);
        webbutton = (Button)findViewById(R.id.webbutton);

        ivPicture = (ImageView) findViewById(R.id.ivPicture);
        textv= (TextView) findViewById(R.id.mytext);

        webbutton.setOnClickListener(this);
    }

    private void decode() {


        if (bmp == null) {
            Log.i("tag", "wtf");
        }
        bmp = bmp.copy(Bitmap.Config.ARGB_8888, true);

        int[] intArray = new int[bmp.getWidth() * bmp.getHeight()];
        bmp.getPixels(intArray, 0, bmp.getWidth(), 0, 0, bmp.getWidth(),
                bmp.getHeight());

        LuminanceSource source = new com.google.zxing.RGBLuminanceSource(
                bmp.getWidth(), bmp.getHeight(), intArray);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Reader reader = new MultiFormatReader();
        try {
            Result result = reader.decode(bitmap);

            text = result.getText();
            byte[] rawBytes = result.getRawBytes();
            BarcodeFormat format = result.getBarcodeFormat();
            ResultPoint[] points = result.getResultPoints();
            textv.setText(text);

        } catch (NotFoundException e) {

            e.printStackTrace();
        } catch (ChecksumException e) {

            e.printStackTrace();
        } catch (FormatException e) {

            e.printStackTrace();

        }
        Log.i("done", "done");
        if(text!=null)
        Toast.makeText(getBaseContext(), text, Toast.LENGTH_LONG).show();
        else{
            Toast.makeText(getBaseContext(), "QQ", Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onClick(View v) {

        Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(i, 0);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK) {
            Bundle extras = data.getExtras();
            bmp = (Bitmap) extras.get("data");
            ivPicture.setImageBitmap(bmp);
            decode();
        }

    }

}

这code会使用手机的默认相机,如果你需要使用自己的客户端,您将需要启动他们的 CaptureActivity ,你的布局应包括的TextView 来显示结果,的ImageView 来显示您拍摄的图像,而按钮启动相机。 。这是基于关闭2.1zxing的。

This code will use your phone's default camera, if you need to use their client, you will need to start their CaptureActivity, Your layout should include a TextView to show results, ImageView to show the image you captured, and Button to start the camera. . This is based off of 2.1zxing.

这篇关于酒吧code / Qr的code阅读器为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆