安卓高级5 zXing
ZXing作者的github地址: https://github.com/zxing/zxing
这里为大家也提供一个封装好的最新的ZXing Lib:
https://github.com/xuyisheng/ZXingLib
下载后关联依赖即可:
案例:
package com.example.administrator.myapplication;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import com.xys.libzxing.zxing.activity.CaptureActivity;
import com.xys.libzxing.zxing.encoding.EncodingUtils;
public class MainActivity extends AppCompatActivity {
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.show);
}
public void onclick(View view) {
Intent intent = new Intent(this,CaptureActivity.class);
startActivityForResult(intent,200);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==200&&resultCode ==RESULT_OK){
String result = data.getStringExtra("result");
Toast.makeText(this, ""+result, Toast.LENGTH_SHORT).show();
}
}
public void onclick2(View view) {
Bitmap bit = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher);
Bitmap bitmap1 = EncodingUtils.createQRCode("他是我的",200,200,bit);
iv.setImageBitmap(bitmap1);
// 获取 内容及二维码图片的 生成Bitmap logo为 二维码中间的 图片展示 1/5大小
// Bitmap bitmap1 = EncodingHandler.enCodeStringWithLogo("多个亲戚不算多!", this, bitmap, 400);
}
}