日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

二维码的扫描与制作

發(fā)布時(shí)間:2025/3/21 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 二维码的扫描与制作 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

參考慕課網(wǎng)

主要使用到谷歌官方支持的zxing開(kāi)源包
zxing開(kāi)源地址:https://github.com/zxing/zxing

但是由于里面不需要的東西太多,很多開(kāi)發(fā)者對(duì)其在安卓方面的api進(jìn)行了抽取,這里我使用了徐宜生所抽取的開(kāi)源包
徐宜生: https://github.com//xuyisheng/ZXingLib



效果圖



工程目錄結(jié)構(gòu)



布局

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"android:orientation="vertical"><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:text="二維碼掃描"android:layout_gravity="center"android:textSize="16sp"android:textColor="#ff0000"android:gravity="center"/><Button android:layout_width="match_parent"android:layout_height="wrap_content"android:text="開(kāi)啟掃描"android:onClick="scan"android:layout_marginTop="20dp"/><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:text="顯示掃描結(jié)果"android:textSize="16sp"/><TextView android:id="@+id/tv_result"android:layout_width="wrap_content"android:layout_height="wrap_content" /><TextView android:layout_width="match_parent"android:layout_height="wrap_content"android:text="二維碼制作"android:layout_gravity="center"android:textSize="16sp"android:textColor="#ff0000"android:gravity="center"android:layout_marginTop="60dp"/><TextView android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="輸入文本"/><EditText android:id="@+id/et_text"android:layout_width="match_parent"android:layout_height="wrap_content"/><CheckBox android:id="@+id/cb_logo"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="logo"/><Button android:layout_width="match_parent"android:layout_height="wrap_content"android:text="創(chuàng)建二維碼"android:onClick="create" /><ImageView android:id="@+id/iv_result"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:background="@mipmap/ic_launcher"/></LinearLayout>



主界面

package com.android.qrcodetest;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.CheckBox; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast;import com.xys.libzxing.zxing.activity.CaptureActivity; import com.xys.libzxing.zxing.encoding.EncodingUtils;public class MainActivity extends AppCompatActivity {private TextView mTextResult;private EditText mInput;private CheckBox mLogo;private ImageView mImageResult;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);mTextResult = (TextView) findViewById(R.id.tv_result);mLogo = (CheckBox) findViewById(R.id.cb_logo);mInput = (EditText) findViewById(R.id.et_text);mImageResult = (ImageView) findViewById(R.id.iv_result);}//掃描二維碼public void scan(View view){startActivityForResult(new Intent(MainActivity.this, CaptureActivity.class),0);}//將得到二維碼信息顯示出來(lái)@Overrideprotected void onActivityResult(int requestCode, int resultCode, Intent data) {super.onActivityResult(requestCode, resultCode, data);if(resultCode == RESULT_OK){Bundle bundle = data.getExtras();String result = bundle.getString("result");mTextResult.setText(result);}}//創(chuàng)建二維碼public void create(View view){String input = mInput.getText().toString();if(input.equals("")){Toast.makeText(MainActivity.this,"輸入不能為空",Toast.LENGTH_SHORT).show();}else{Bitmap bitmap = EncodingUtils.createQRCode(input,500,500,mLogo.isChecked() ? BitmapFactory.decodeResource(getResources(),R.drawable.logo) : null);mImageResult.setImageBitmap(bitmap);}}}



完整代碼地址:https://github.com/xkck/QRCodeTest

總結(jié)

以上是生活随笔為你收集整理的二维码的扫描与制作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。