Android开发之二维码的生成与解析
随着科技的迅猛发展,二维码在人们的日常生活中扮演着越来越重要的角色,本人对于一些新事物,新特性颇感兴趣,经过一段时间的研究,终于实现了在Android端生成二维码,解析二维码等功能,下面贴出代码,望各路大神批评指正,感激不尽,灰常感谢♪(^∇^*)
先上效果图:
核心代码如下:
MainActivity
package com.hxht.testallstyleqrcode; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.text.TextUtils; import android.view.View; import android.widget.EditText; 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.DecodeHintType; import com.google.zxing.EncodeHintType; import com.google.zxing.FormatException; import com.google.zxing.NotFoundException; import com.google.zxing.Result; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.google.zxing.common.HybridBinarizer; import com.google.zxing.qrcode.QRCodeReader; import com.google.zxing.qrcode.QRCodeWriter; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Hashtable; import java.util.Map; public class MainActivity extends AppCompatActivity { private EditText et_desc; private ImageView iv; private static final int IMAGEWIDTH = 40; private static final int IMAGEHEIGHT = 40; private static final int QRCODEWIDTH = 300; private static final int QRCODEHEIGHT = 300; private static final int HALFIMAGEWIDTH = IMAGEWIDTH / 2; private static final int HALFIMAGEHEIGHT = IMAGEHEIGHT / 2; private Bitmap scaledBitmap; private TextView tv_result; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);