# QRCodeView
**Repository Path**: villager/QRCodeView
## Basic Information
- **Project Name**: QRCodeView
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2019-11-11
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## QRCodeView
基于 com.google.zxing 开发,用于简化 Android 设备扫描、生成二维码等操作。
## 前言
[QRCodeView](https://github.com/0xZhangKe/QRCodeView) 基于 Google 的 [zxing](https://github.com/zxing/zxing) 进行二次开发,简化二维码的相关操作、优化识别速度。由于整个 zxing 框架中不仅包含了二维码识别相关的代码,还包括其他格式如条形码等等的代码,体量较大,实际开发中一般只需要使用二维码,故本项目中删除了不必要的代码。本项目不仅提供了使用摄像头预览实时识别二维码,还有如生成一张二维码图片,生成一张带有 logo 的二维码图片等等。
**注意:此项目只支持二维码,不支持其他格式的条码!**
## 效果图
## 集成方式
在 app/build.gradle 中添加依赖:
```
implementation 'com.github.0xZhangKe:QRCodeView:1.3'
```
如果依赖失败还要在根目录的 builde.gradle 中添加仓库:
```
maven { url = 'https://jitpack.io' }
```
## 使用方式
使用起来很简单,先看一下布局文件:
```xml
**Public constructors** ``` public QRCodeView(Context context) public QRCodeView(Context context, AttributeSet attrs) public QRCodeView(Context context, AttributeSet attrs, int defStyleAttr) ``` **Public methods** name| describe ------| ------ void startPreview() | 开始预览,一般在 onResume() 中调用 void stopPreview() | 停止预览,一般在 onPause() 中调用 boolean isPreview() | 当前是否正在预览 Camera getCamera() | 获取 Camera 对象 void setOnQRCodeListener(OnQRCodeRecognitionListener onQRCodeListener) | 设置二维码识别监听器 ### OnQRCodeRecognitionListener **包名:** ``` com.zhangke.qrcodeview.QRCodeViewView ``` **描述:** 二维码识别监听器 name| describe ------| ------ void onQRCodeRecognition(Result result) | 识别到二维码时会回调此方法 ### QRCodeUtil **包名:** ``` com.zhangke.qrcodeview ``` **描述:** 二维码相关工具类。 name| describe ------| ------ static Bitmap createQRCode(String text) throws WriterException | 根据文本创建二维码图片 static Bitmap createQRCode(String text, Bitmap logo) | 根据文本及 logo 创建一个带有 logo 的二维码图片 static String decodeQRCode(Bitmap bitmap) | 识别一张二维码图片,返回其中的文本
如果觉得还不错的话,欢迎关注我的个人公众号,我会不定期发一些干货文章~  也可以加我微信: 