基于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.mzph.cn/news/278217.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

如何在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. 如果您…

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; 您无需…

在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…

如何在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…

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…

如何在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…

设置微软应用商店的代理_如何设置和使用Microsoft家庭安全应用

设置微软应用商店的代理The Microsoft Family Safety app provides a set of reporting and parental control tools for people with Microsoft accounts. With filtering controls, location reporting, and app-usage recording, this app gives parents a way to monitor t…

Linux跨平台远程控制

转载于:https://blog.51cto.com/13660858/2094987

Zoom Host可以真正看到您的所有私人消息吗?

Girts Ragelis/Shutterstock.comGirts Ragelis / Shutterstock.comViral social media posts are alleging that Zoom’s private messages aren’t really private—if you’re chatting privately during a Zoom meeting, the host can see your entire conversation. Is tha…

使用Keras进行深度学习:(三)使用text-CNN处理自然语言(上)

欢迎大家关注我们的网站和系列教程&#xff1a;http://www.tensorflownews.com/&#xff0c;学习更多的机器学习、深度学习的知识&#xff01; 上一篇文章中一直围绕着CNN处理图像数据进行讲解&#xff0c;而CNN除了处理图像数据之外&#xff0c;还适用于文本分类。CNN模型首次…

powerpoint转换器_如何将PowerPoint演示文稿转换为主题演讲

powerpoint转换器If someone sends you a Microsoft PowerPoint presentation, but you’d rather use Apple’s presentation software, Keynote, you’re in luck! Apple’s done all the hard work for you. Here’s how to convert a PowerPoint presentation to Keynote. …

Android高仿大众点评(带服务端)

2019独角兽企业重金招聘Python工程师标准>>> 实例讲解了一个类似大众点评的项目&#xff0c;项目包含服务端和android端源码, 服务端为php代码&#xff0c;如果没有接触过php, 文章中讲解一键部署php的方法&#xff0c;让您5分钟将服务端搭建成功, 您也可以将php换成…

vista任务栏透明_在Windows XP中获取Vista任务栏缩略图预览

vista任务栏透明It was only a matter of time before people started cloning Windows Vista features and adding them into Windows XP. One of my favorite Vista features is the thumbnails that popup when you mouse over the taskbar. And now I can use them in XP a…

Spring实战Day2

创建对象之后如何体现对象之间的依赖&#xff1f; Spring容器负责创建Bean和依赖注入&#xff0c;那么Spring是怎么将Bean装配在一起的呢&#xff1f; Spring提供了三种方式装配机制 1.隐式的bean发现机制和自动装配 图一图二&#xff0c;是两个组件与Config类同包 图三&#x…