Android 扫描二维码条形码、识别相册里的二维码图片、生成带 Logo 二维码、支持微博微信 QQ 二维码扫描样式

阅读 4531
收藏 313
2016-08-02
原文链接:github.com

License Maven Central

根据公司项目需求,参考这个项目改的 barcodescanner

主要功能:ZXing生成二维码、ZXing扫描二维码、ZBar扫描二维码(扫描中文会有乱码)、可控制闪光灯和定制各式各样的扫描框

效果图

Image of ZXingDemo Image of ZBarDemo Image of IqeggQRCodeDemo

点击下载ZXingDemo.apk或扫描下面的二维码安装 点击下载ZBarDemo apk或扫描下面的二维码安装
ZXingDemo apk文件二维码 ZBarDemo apk文件二维码

Gradle依赖

ZXing

dependencies {
    compile 'com.google.zxing:core:3.1.0'
    compile 'cn.bingoogolapple:qrcodecore:latestVersion@aar'
    compile 'cn.bingoogolapple:zxing:latestVersion@aar'
}

ZBar

dependencies {
    compile 'cn.bingoogolapple:qrcodecore:latestVersion@aar'
    compile 'cn.bingoogolapple:zbar:latestVersion@aar'
}

Layout

ZXing

ZBar

自定义属性说明

属性名 说明 默认值
qrcv_topOffset 扫描框距离扫描视图顶部的距离 80dp
qrcv_cornerSize 扫描框边角线的宽度 2dp
qrcv_cornerLength 扫描框边角线的长度 20dp
qrcv_cornerColor 扫描框边角线的颜色 @android:color/white
qrcv_rectWidth 扫描框的宽度 200dp
qrcv_maskColor 除去扫描框,其余部分阴影颜色 #33ffffff
qrcv_scanLineSize 扫描线的宽度 1dp
qrcv_scanLineColor 扫描线的颜色 @android:color/white

接口说明

QRCodeView

/**
 * 显示扫描框
 */
public void showScanRect()

/**
 * 隐藏扫描框
 */
public void hiddenScanRect()

/**
 * 打开摄像头开始预览,但是并未开始识别
 */
public void startCamera()

/**
 * 关闭摄像头预览,并且隐藏扫描框
 */
public void stopCamera()

/**
 * 延迟1.5秒后开始识别
 */
public void startSpot()

/**
 * 延迟delay毫秒后开始识别
 *
 * @param delay
 */
public void startSpotDelay(int delay)

/**
 * 停止识别
 */
public void stopSpot()

/**
 * 停止识别,并且隐藏扫描框
 */
public void stopSpotAndHiddenRect()

/**
 * 显示扫描框,并且延迟1.5秒后开始识别
 */
public void startSpotAndShowRect()

/**
 * 打开闪光灯
 */
public void openFlashlight()

/**
 * 关闭散光灯
 */
public void closeFlashlight()

ResultHandler

/**
 * 处理扫描结果
 *
 * @param result
 */
void handleResult(String result)

/**
 * 处理打开相机出错
 */
void handleCameraError()

详细用法请查看ZBarDemo:feet:

详细用法请查看ZXingDemo:feet:

关于我

License

Copyright 2015 bingoogolapple

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
评论