Skip to content

Commit aa31357

Browse files
committed
修复设置扫描格式之后无法扫码的问题
1 parent aaecfa2 commit aa31357

17 files changed

Lines changed: 74 additions & 51 deletions

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,26 @@
44
# CZXing
55
C++ port of ZXing for Android
66

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

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

1111
### 使用
1212
在gradle中:
1313
``` groovy
14-
implementation 'me.devilsen:CZXing:0.9.10'
14+
implementation 'me.devilsen:CZXing:0.9.11'
1515
```
1616
建议加入abiFilters
1717
```gradle
18-
defaultConfig {
19-
20-
// 其他设置...
21-
22-
ndk {
23-
// 设置支持的so库架构,设置一个可以减小包的大小
24-
abiFilters "armeabi-v7a","arm64-v8a"
25-
}
18+
defaultConfig {
19+
20+
// 其他设置...
21+
22+
ndk {
23+
// 设置支持的so库架构,设置一个可以减小包的大小
24+
abiFilters "armeabi-v7a","arm64-v8a"
2625
}
26+
}
2727
```
2828
如果下载失败,可以在根目录加入阿里云的镜像
2929
```gradle
@@ -118,7 +118,7 @@ BarcodeWriter writer = new BarcodeWriter();
118118
Bitmap bitmap = writer.write("Hello World", BarCodeUtil.dp2px(this, 200), BarCodeUtil.dp2px(this, 200), Color.RED);
119119
```
120120

121-
复杂调用
121+
完整调用
122122

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

139+
### 4. 测试Case
140+
| | | |
141+
:--:|:-:|:--:
142+
![](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)
143+
![](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)
144+
138145
### 效果展示
139146
[远距离扫码演示](https://www.bilibili.com/video/av59888116)
140147

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ buildscript {
2727
google()
2828
}
2929
dependencies {
30-
classpath 'com.android.tools.build:gradle:3.5.2'
30+
classpath 'com.android.tools.build:gradle:3.5.3'
3131
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
3232
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
3333
// classpath 'com.tencent.bugly:symtabfileuploader:2.2.1'

czxing/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
defaultConfig {
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
9-
versionCode 22
10-
versionName "0.9.10"
9+
versionCode 23
10+
versionName "0.9.11"
1111

1212
externalNativeBuild {
1313
cmake {

czxing/src/main/cpp/zxing/src/MultiFormatReader.cpp

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ namespace ZXing {
3333

3434
MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
3535
{
36+
setFormat(hints);
37+
}
38+
39+
MultiFormatReader::~MultiFormatReader()
40+
{
41+
}
42+
43+
void MultiFormatReader::setFormat(const DecodeHints &hints)
44+
{
45+
_readers.clear();
3646
bool tryHarder = hints.shouldTryHarder();
37-
if (hints.hasNoFormat()) {
38-
bool addOneDReader =
47+
bool addOneDReader =
3948
hints.hasFormat(BarcodeFormat::UPC_A) ||
4049
hints.hasFormat(BarcodeFormat::UPC_E) ||
4150
hints.hasFormat(BarcodeFormat::EAN_13) ||
@@ -48,29 +57,28 @@ MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
4857
hints.hasFormat(BarcodeFormat::RSS_14) ||
4958
hints.hasFormat(BarcodeFormat::RSS_EXPANDED);
5059

51-
// Put 1D readers upfront in "normal" mode
52-
if (addOneDReader && !tryHarder) {
53-
_readers.emplace_back(new OneD::Reader(hints));
54-
}
55-
if (hints.hasFormat(BarcodeFormat::QR_CODE)) {
56-
_readers.emplace_back(new QRCode::Reader(hints));
57-
}
58-
if (hints.hasFormat(BarcodeFormat::DATA_MATRIX)) {
59-
_readers.emplace_back(new DataMatrix::Reader(hints));
60-
}
61-
if (hints.hasFormat(BarcodeFormat::AZTEC)) {
62-
_readers.emplace_back(new Aztec::Reader());
63-
}
64-
if (hints.hasFormat(BarcodeFormat::PDF_417)) {
65-
_readers.emplace_back(new Pdf417::Reader());
66-
}
67-
if (hints.hasFormat(BarcodeFormat::MAXICODE)) {
68-
_readers.emplace_back(new MaxiCode::Reader());
69-
}
70-
// At end in "try harder" mode
71-
if (addOneDReader && tryHarder) {
72-
_readers.emplace_back(new OneD::Reader(hints));
73-
}
60+
// Put 1D readers upfront in "normal" mode
61+
if (addOneDReader && !tryHarder) {
62+
_readers.emplace_back(new OneD::Reader(hints));
63+
}
64+
if (hints.hasFormat(BarcodeFormat::QR_CODE)) {
65+
_readers.emplace_back(new QRCode::Reader(hints));
66+
}
67+
if (hints.hasFormat(BarcodeFormat::DATA_MATRIX)) {
68+
_readers.emplace_back(new DataMatrix::Reader(hints));
69+
}
70+
if (hints.hasFormat(BarcodeFormat::AZTEC)) {
71+
_readers.emplace_back(new Aztec::Reader());
72+
}
73+
if (hints.hasFormat(BarcodeFormat::PDF_417)) {
74+
_readers.emplace_back(new Pdf417::Reader());
75+
}
76+
if (hints.hasFormat(BarcodeFormat::MAXICODE)) {
77+
_readers.emplace_back(new MaxiCode::Reader());
78+
}
79+
// At end in "try harder" mode
80+
if (addOneDReader && tryHarder) {
81+
_readers.emplace_back(new OneD::Reader(hints));
7482
}
7583

7684
if (_readers.empty()) {
@@ -88,16 +96,6 @@ MultiFormatReader::MultiFormatReader(const DecodeHints& hints)
8896
}
8997
}
9098

91-
MultiFormatReader::~MultiFormatReader()
92-
{
93-
}
94-
95-
void MultiFormatReader::setFormat(const DecodeHints &hints)
96-
{
97-
_readers.clear();
98-
_readers.emplace_back(new OneD::Reader(hints));
99-
}
100-
10199
Result
102100
MultiFormatReader::read(const BinaryBitmap& image) const
103101
{

czxing/src/main/java/me/devilsen/czxing/view/BarCoderView.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,22 @@ public void onDestroy() {
449449
public void setScanMode(int scanMode) {
450450
this.scanMode = scanMode;
451451
}
452+
453+
/**
454+
* 打开闪光灯
455+
*/
456+
public void openFlashlight() {
457+
if (mCameraSurface != null) {
458+
mCameraSurface.openFlashlight();
459+
}
460+
}
461+
462+
/**
463+
* 关闭闪光灯
464+
*/
465+
public void closeFlashlight() {
466+
if (mCameraSurface != null) {
467+
mCameraSurface.closeFlashlight();
468+
}
469+
}
452470
}

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ dependencies {
5858

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

6363
implementation rootProject.ext.appcompat
6464
testImplementation rootProject.ext.junit

sample/src/main/res/layout/activity_customize_scan.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
android:layout_width="wrap_content"
5656
android:layout_height="wrap_content"
5757
android:layout_centerHorizontal="true"
58-
android:layout_marginTop="550dp"
58+
android:layout_marginTop="450dp"
5959
android:background="?attr/selectableItemBackground"
6060
android:text="我的二维码"
6161
android:textColor="@color/colorAccent"

screenshots/case/test_bar_code.png

53.7 KB
Loading
8.33 KB
Loading

screenshots/case/test_blurry.png

62.5 KB
Loading

0 commit comments

Comments
 (0)