基于ZXing Android實現生成二維碼圖片和相機掃描二維碼圖片即時解碼的功能

NextQRCode ZXing開源庫的精簡版

**基于ZXing Android實現生成二維碼圖片和相機掃描二維碼圖片即時解碼的功能
原文博客 附源碼下載地址**

圖片描述

與原ZXingMini項目對比

NextQRCode做了重大架構修改,原ZXingMini項目與當前NextQRCode不兼容

圖片描述

dependencies {compile 'com.github.yoojia:next-qrcode:2.0-2'...
}

生成二維碼圖案

圖片描述

// 二維碼中間圖標
final Bitmap centerImage = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
// 生成的二維碼圖案
Bitmap qrCodeImage = new QRCodeEncoder.Builder().width(size) // 二維碼圖案的寬度.height(size).paddingPx(0) // 二維碼的內邊距.marginPt(3) // 二維碼的外邊距.centerImage(centerImage) // 二維碼中間圖標.build().encode(content);

二維碼解碼

final QRCodeDecoder mDecoder = new QRCodeDecoder.Builder().build();
// 傳入二維碼圖案Bitmap對象然后解碼成文本內容
String content = mDecoder.decode(bitmap);

使用 LiveCameraView 自動掃描解碼

public class QRCodeScanActivity extends AppCompatActivity {public static final String TAG = QRCodeScanActivity.class.getSimpleName();private LiveCameraView mLiveCameraView;private ImageView mCaptureImage;private TextView mContentView;private final CaptureCallback mCaptureCallback = new CaptureCallback() {@Override public void onCaptured(Bitmap bitmap) {Log.i(TAG, "-> Got bitmap, show to capture view");mCaptureImage.setImageBitmap(bitmap);Observable.just(bitmap).map(new Func1<Bitmap, String>() {private final QRCodeDecoder mDecoder = new QRCodeDecoder.Builder().build();@Overridepublic String call(Bitmap bitmap) {return mDecoder.decode(bitmap);}}).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<String>() {@Override public void call(String content) {mContentView.setText(content);}});}};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);Window window = getWindow();window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);setContentView(R.layout.activity_scan);mCaptureImage = (ImageView) findViewById(R.id.capture_image);mContentView = (TextView) findViewById(R.id.content);mLiveCameraView = (LiveCameraView) findViewById(R.id.capture_preview_view);mLiveCameraView.setPreviewReadyCallback(new CameraPreviewView.PreviewReadyCallback() {@Overridepublic void onStarted(Camera camera) {Log.i(TAG, "-> Camera started, start to auto capture");mLiveCameraView.startAutoCapture(1500, mCaptureCallback);}@Overridepublic void onStopped() {Log.i(TAG, "-> Camera stopped");mLiveCameraView.stopAutoCapture();}});}}

**基于ZXing Android實現生成二維碼圖片和相機掃描二維碼圖片即時解碼的功能
原文博客 附源碼下載地址**

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278217.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278217.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278217.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

flask sqlalchemy 單表查詢

主要內容: 1 sqlalchemy: 一個python的ORM框架 2 使用sqlalchemy 的流程: 創建一個類 創建數據庫引擎 將所有的類序列化成數據表 進行增刪改查操作 # 1.創建一個 Class from sqlalchemy.ext.declarative import declarative_base Base declarative_base() # Base 是 ORM模型 基…

如何在Windows 7或Vista上安裝IIS

If you are a developer using ASP.NET, one of the first things you’ll want to install on Windows 7 or Vista is IIS (internet information server). Keep in mind that your version of Windows may not come with IIS. I’m using Windows 7 Ultimate edition. 如果您…

Dubbo的使用及原理淺析

https://www.cnblogs.com/wang-meng/p/5791598.html轉載于:https://www.cnblogs.com/h-wt/p/10490345.html

ThinkPHP3.2 實現阿里云OSS上傳文件

為什么80%的碼農都做不了架構師&#xff1f;>>> 0、配置文件Config&#xff0c;加入OSS配置選項&#xff0c;設置php.ini最大上傳大小&#xff08;自行解決&#xff0c;這里不做演示&#xff09; OSS > array(ACCESS_KEY_ID > **************, //從OSS獲得的…

ipad和iphone切圖_如何在iPhone,iPad和Mac上簽名PDF

ipad和iphone切圖Khamosh PathakKhamosh PathakDo you have documents to sign? You don’t need to worry about printing, scanning, or even downloading a third-party app. You can sign PDFs right on your iPhone, iPad, and Mac. 你有文件要簽名嗎&#xff1f; 您無需…

一個頁面上有大量的圖片(大型電商網站),加載很慢,你有哪些方法優化這些圖片的加載,給用戶更好的體驗。...

a. 圖片懶加載&#xff0c;滾動到相應位置才加載圖片。 b. 圖片預加載&#xff0c;如果為幻燈片、相冊等&#xff0c;將當前展示圖片的前一張和后一張優先下載。 c. 使用CSSsprite&#xff0c;SVGsprite&#xff0c;Iconfont、Base64等技術&#xff0c;如果圖片為css圖片的話。…

[function.require]: Failed opening required 杰奇cms

在配置杰奇cms移動端的時候&#xff0c;出現了[function.require]: Failed opening required 不要慌&#xff0c;百度一下即可解決。這個就是權限問題。由于移動端要請求pc端的文件&#xff0c;沒權限。加上一個iis_iusrs讀寫權限即可搞定&#xff01;轉載于:https://www.cnblo…

在Ubuntu服務器上打開第二個控制臺會話

Ubuntu Server has the native ability to run multiple console sessions from the server console prompt. If you are working on the actual console and are waiting for a long running command to finish, there’s no reason why you have to sit and wait… you can j…

Cloudstack系統配置(三)

系統配置 CloudStack提供一個基于web的UI&#xff0c;管理員和終端用戶能夠使用這個界面。用戶界面版本依賴于登陸時使用的憑證不同而不同。用戶界面是適用于大多數流行的瀏覽器包括IE7,IE8,IE9,Firefox Chrome等。URL是:(用你自己的管理控制服務器IP地址代替) 1http://<ma…

.NET Core 3.0-preview3 發布

.NET Core 3.0 Preview 3已經發布&#xff0c;框架和ASP.NET Core有許多有趣的更新。這是最重要的更新列表。 下載地址 :https://aka.ms/netcore3download 。.NET Core 3.0的更新&#xff1a;C&#xff03;中對索引和范圍的更多支持支持.NET Standard 2.1。以.NET Standard項目…

如何在Chrome工具欄中固定和取消固定擴展程序

Not all extensions are made equal. Some extensions, like Grammarly, work quietly in the background and don’t need an icon in the Chrome toolbar. Here’s how to pin and unpin extensions for a cleaner Chrome toolbar. 并非所有擴展名都相等。 某些擴展程序(例如…

vim編輯器快捷操作

1、查找 進入編輯器 按下 / 進行查找&#xff0c;回跳到第一個匹配的值&#xff0c;按下n查找下一個 N返回查看上一個 也可根據正則進行查找 2、替換 &#xff1a;s/a/b/g 當前行替換 &#xff1a;%s/a/b/g 全文替換 &#xff1a;5,10s/a/b/g 區域替換: .,2s/foo/bar/g 當…

react-navigation 跨 tabs 返回首頁

2019獨角獸企業重金招聘Python工程師標準>>> react-navigation 跨 tabs 返回首頁 import { NavigationActions } from react-navigation;const navigationAction NavigationActions.reset({ index: 0,actions: [ NavigationActions.navigate({ routeName: RootTab…

MySql:從任何主機授予根用戶登錄權限

Note that this is Not very secure, and should only be used for a local development box where you don’t feel like setting up individual permissions, but still need to connect from other machines. 請注意&#xff0c;這不是很安全&#xff0c;僅應用于您不想設置…

ubuntu 默認命令行_從命令行在Ubuntu上設置默認瀏覽器

ubuntu 默認命令行Ubuntu Linux has a default browser functionality that will automatically launch the correct browser when clicking on a link in a gnome gui application. It’s easy enough to set the default browser using the GUI tools, but sometimes it’s e…

ThreadLocal就是這么簡單

前言 今天要研究的是ThreadLocal&#xff0c;這個我在一年前學習JavaWeb基礎的時候接觸過一次&#xff0c;當時在baidu搜出來的第一篇博文ThreadLocal&#xff0c;在評論下很多開發者認為那博主理解錯誤&#xff0c;給出了很多有關的鏈接來指正(可原博主可能沒上博客了&#xf…

sublime python配置運行

1、安裝python環境 安裝完成時&#xff0c;WinR → 輸入cmd → Enter → 調出來命令行&#xff0c;輸入python確認安裝是否成功。 2、安裝sublime 3、打開sublime&#xff0c;選擇工具——編譯系統——新建編譯系統&#xff0c;復制粘貼下面文件。保存為python3,選擇工具——編…

Linux 終端環境安裝 L2TP 客戶端

安裝&#xff1a; yum -y install xl2tpd ppp 安裝成功后&#xff0c;直接進入配置流程 配置&#xff1a; 配置過程也并不復雜&#xff0c;主要有兩個文件。首先就是配置 /etc/xl2tpd/xl2tpd.conf 文件。此文件原有的內容是做服務端用的&#xff0c;而作為客戶端使用只需保留如…

如何在Twitch上設置捐款

Many people on Twitch stream as a hobby. If you’re thinking about going full-time, though, you’ll need to raise some cash. Setting up donations on Twitch is one way you can do it! Twitch上的許多人都將其作為愛好。 但是&#xff0c;如果您打算全職工作&#x…

JAVA-Concurrency之CountDownLatch說明

2019獨角獸企業重金招聘Python工程師標準>>> As per java docs, CountDownLatch is a synchronization aid that allows one or more threads to wait until a set of operations being performed in other threads completes. CountDownLatch concept is very comm…