Skip to content

Commit

Permalink
修复设置扫描格式之后无法扫码的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
devilsen committed Dec 8, 2019
1 parent aaecfa2 commit aa31357
Show file tree
Hide file tree
Showing 17 changed files with 74 additions and 51 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@
# CZXing
C++ port of ZXing for Android

底层使用C++来处理图像及解析二维码,并且加入了OpenCV来解析图像,可以在更远的距离识别出二维码
底层使用C++来处理图像及解析二维码,并且加入了OpenCV来解析图像,可以在更远的距离识别出更加复杂的二维码

![App展示](https://github.com/devilsen/CZXing/blob/master/screenshots/scan_code.gif)

### 使用
在gradle中:
``` groovy
implementation 'me.devilsen:CZXing:0.9.10'
implementation 'me.devilsen:CZXing:0.9.11'
```
建议加入abiFilters
```gradle
defaultConfig {
// 其他设置...
ndk {
// 设置支持的so库架构,设置一个可以减小包的大小
abiFilters "armeabi-v7a","arm64-v8a"
}
defaultConfig {
// 其他设置...
ndk {
// 设置支持的so库架构,设置一个可以减小包的大小
abiFilters "armeabi-v7a","arm64-v8a"
}
}
```
如果下载失败,可以在根目录加入阿里云的镜像
```gradle
Expand Down Expand Up @@ -118,7 +118,7 @@ BarcodeWriter writer = new BarcodeWriter();
Bitmap bitmap = writer.write("Hello World", BarCodeUtil.dp2px(this, 200), BarCodeUtil.dp2px(this, 200), Color.RED);
```

复杂调用
完整调用

```java
/**
Expand All @@ -133,8 +133,15 @@ Bitmap bitmap = writer.write("Hello World", BarCodeUtil.dp2px(this, 200), BarCod
* @return 条码bitmap
*/
private Bitmap write(String text, int width, int height, int color, BarcodeFormat format, Bitmap logo)

```

### 4. 测试Case
| | | |
:--:|:-:|:--:
![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_bar_code.png)|![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_black_boder.png)|![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_color.png)
![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_gray.png)|![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_oblique.png)|![](https://github.com/devilsen/CZXing/blob/master/screenshots/case/test_oblique_2.png)

### 效果展示
[远距离扫码演示](https://www.bilibili.com/video/av59888116)

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.android.tools.build:gradle:3.5.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
// classpath 'com.tencent.bugly:symtabfileuploader:2.2.1'
Expand Down
4 changes: 2 additions & 2 deletions czxing/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 22
versionName "0.9.10"
versionCode 23
versionName "0.9.11"

externalNativeBuild {
cmake {
Expand Down
68 changes: 33 additions & 35 deletions czxing/src/main/cpp/zxing/src/MultiFormatReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,18 @@ namespace ZXing {

MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
{
setFormat(hints);
}

MultiFormatReader::~MultiFormatReader()
{
}

void MultiFormatReader::setFormat(const DecodeHints &hints)
{
_readers.clear();
bool tryHarder = hints.shouldTryHarder();
if (hints.hasNoFormat()) {
bool addOneDReader =
bool addOneDReader =
hints.hasFormat(BarcodeFormat::UPC_A) ||
hints.hasFormat(BarcodeFormat::UPC_E) ||
hints.hasFormat(BarcodeFormat::EAN_13) ||
Expand All @@ -48,29 +57,28 @@ MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
hints.hasFormat(BarcodeFormat::RSS_14) ||
hints.hasFormat(BarcodeFormat::RSS_EXPANDED);

// Put 1D readers upfront in "normal" mode
if (addOneDReader && !tryHarder) {
_readers.emplace_back(new OneD::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::QR_CODE)) {
_readers.emplace_back(new QRCode::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::DATA_MATRIX)) {
_readers.emplace_back(new DataMatrix::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::AZTEC)) {
_readers.emplace_back(new Aztec::Reader());
}
if (hints.hasFormat(BarcodeFormat::PDF_417)) {
_readers.emplace_back(new Pdf417::Reader());
}
if (hints.hasFormat(BarcodeFormat::MAXICODE)) {
_readers.emplace_back(new MaxiCode::Reader());
}
// At end in "try harder" mode
if (addOneDReader && tryHarder) {
_readers.emplace_back(new OneD::Reader(hints));
}
// Put 1D readers upfront in "normal" mode
if (addOneDReader && !tryHarder) {
_readers.emplace_back(new OneD::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::QR_CODE)) {
_readers.emplace_back(new QRCode::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::DATA_MATRIX)) {
_readers.emplace_back(new DataMatrix::Reader(hints));
}
if (hints.hasFormat(BarcodeFormat::AZTEC)) {
_readers.emplace_back(new Aztec::Reader());
}
if (hints.hasFormat(BarcodeFormat::PDF_417)) {
_readers.emplace_back(new Pdf417::Reader());
}
if (hints.hasFormat(BarcodeFormat::MAXICODE)) {
_readers.emplace_back(new MaxiCode::Reader());
}
// At end in "try harder" mode
if (addOneDReader && tryHarder) {
_readers.emplace_back(new OneD::Reader(hints));
}

if (_readers.empty()) {
Expand All @@ -88,16 +96,6 @@ MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
}
}

MultiFormatReader::~MultiFormatReader()
{
}

void MultiFormatReader::setFormat(const DecodeHints &hints)
{
_readers.clear();
_readers.emplace_back(new OneD::Reader(hints));
}

Result
MultiFormatReader::read(const BinaryBitmap& image) const
{
Expand Down
18 changes: 18 additions & 0 deletions czxing/src/main/java/me/devilsen/czxing/view/BarCoderView.java
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,22 @@ public void onDestroy() {
public void setScanMode(int scanMode) {
this.scanMode = scanMode;
}

/**
* 打开闪光灯
*/
public void openFlashlight() {
if (mCameraSurface != null) {
mCameraSurface.openFlashlight();
}
}

/**
* 关闭闪光灯
*/
public void closeFlashlight() {
if (mCameraSurface != null) {
mCameraSurface.closeFlashlight();
}
}
}
2 changes: 1 addition & 1 deletion sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ dependencies {

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'
// implementation project(':czxing')
implementation 'me.devilsen:CZXing:0.9.10'
implementation 'me.devilsen:CZXing:0.9.11'

implementation rootProject.ext.appcompat
testImplementation rootProject.ext.junit
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/res/layout/activity_customize_scan.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="550dp"
android:layout_marginTop="450dp"
android:background="?attr/selectableItemBackground"
android:text="我的二维码"
android:textColor="@color/colorAccent"
Expand Down
Binary file added screenshots/case/test_bar_code.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_black_boder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_blurry.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_blurry_2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_boder_complex_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_boder_complex_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_color.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_gray.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_oblique.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added screenshots/case/test_oblique_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aa31357

Please sign in to comment.