Skip to content

Commit 9d320c0

Browse files
committed
修复横屏崩溃的问题
1 parent 9529768 commit 9d320c0

9 files changed

Lines changed: 29 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ C++ port of ZXing for Android
99
### 使用
1010
在gradle中:
1111
``` groovy
12-
implementation 'me.devilsen:CZXing:0.8.7'
12+
implementation 'me.devilsen:CZXing:0.8.8'
1313
```
1414
建议加入abiFilters
1515
```gradle

czxing/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ android {
77
minSdkVersion rootProject.ext.minSdkVersion
88
targetSdkVersion rootProject.ext.targetSdkVersion
99
versionCode 14
10-
versionName "0.8.7"
10+
versionName "0.8.8"
1111

1212
externalNativeBuild {
1313
cmake {

czxing/src/main/cpp/ImageScheduler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ ImageScheduler::process(jbyte *bytes, int left, int top, int cropWidth, int crop
4040
}
4141
isProcessing = true;
4242

43-
LOGE("process begin...");
43+
// LOGE("process begin...");
4444

4545
frameData.bytes = bytes;
4646
frameData.left = left;
@@ -81,7 +81,7 @@ void ImageScheduler::readyMat() {
8181
Mat gray;
8282
cvtColor(src, gray, COLOR_RGBA2GRAY);
8383

84-
LOGE("start decode...");
84+
// LOGE("start decode...");
8585
decodeGrayPixels(gray);
8686
}
8787

@@ -223,7 +223,7 @@ Result ImageScheduler::decodePixels(Mat mat) {
223223
}
224224

225225
bool ImageScheduler::analysisBrightness(const FrameData frameData) {
226-
LOGE("start analysisBrightness...");
226+
// LOGE("start analysisBrightness...");
227227

228228
// 像素点的总亮度
229229
unsigned long pixelLightCount = 0L;

czxing/src/main/cpp/zxing/src/qrcode/QRFinderPatternFinder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ static float CrossCheckVertical(const BitMatrix& image, int startI, int centerJ,
208208
stateCount[4]++;
209209
i++;
210210
}
211-
// if (stateCount[4] >= maxCount) {
212-
// return std::numeric_limits<float>::quiet_NaN();
213-
// }
211+
if (stateCount[4] >= maxCount && stateCount[0] > maxCount) {
212+
return std::numeric_limits<float>::quiet_NaN();
213+
}
214214

215215
// If we found a finder-pattern-like section, but its size is more than 40% different than
216216
// the original, assume it's a false positive
@@ -274,9 +274,9 @@ static float CrossCheckHorizontal(const BitMatrix& image, int startJ, int center
274274
stateCount[4]++;
275275
j++;
276276
}
277-
// if (stateCount[4] >= maxCount) {
278-
// return std::numeric_limits<float>::quiet_NaN();
279-
// }
277+
if (stateCount[4] >= maxCount && stateCount[0] > maxCount) {
278+
return std::numeric_limits<float>::quiet_NaN();
279+
}
280280

281281
// If we found a finder-pattern-like section, but its size is significantly different than
282282
// the original, assume it's a false positive

czxing/src/main/java/me/devilsen/czxing/ScanActivity.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ private void initData() {
9999
@Override
100100
protected void onStart() {
101101
super.onStart();
102-
mScanView.openCamera(); // 打开后置摄像头开始预览,但是并未开始识别
103-
mScanView.startScan(); // 显示扫描框,并开始识别
102+
// mScanView.openCamera(); // 打开后置摄像头开始预览,但是并未开始识别
103+
// mScanView.startScan(); // 显示扫描框,并开始识别
104104
}
105105

106106
@Override
@@ -123,8 +123,8 @@ protected void onPause() {
123123

124124
@Override
125125
protected void onStop() {
126-
mScanView.stopScan();
127-
mScanView.closeCamera(); // 关闭摄像头预览,并且隐藏扫描框
126+
// mScanView.stopScan();
127+
// mScanView.closeCamera(); // 关闭摄像头预览,并且隐藏扫描框
128128
super.onStop();
129129
}
130130

czxing/src/main/java/me/devilsen/czxing/util/ResolutionAdapterUtil.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package me.devilsen.czxing.util;
22

3+
import android.content.Context;
4+
5+
import me.devilsen.czxing.camera.CameraUtil;
6+
37
/**
48
* desc : 分辨率转换util
59
* date : 2019-08-20 17:07
@@ -23,10 +27,10 @@ public void setResolutionSize(int resolutionWidth, int resolutionHeight) {
2327
setRatio();
2428
}
2529

26-
public void setCameraSize(int cameraWidth, int cameraHeight) {
30+
public void setCameraSize(boolean portrait, int cameraWidth, int cameraHeight) {
2731
this.cameraWidth = cameraWidth;
2832
this.cameraHeight = cameraHeight;
29-
if (cameraWidth > cameraHeight) {
33+
if (portrait) {
3034
int temp = this.cameraWidth;
3135
this.cameraWidth = this.cameraHeight;
3236
this.cameraHeight = temp;

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.Rect;
66
import android.hardware.Camera;
77
import android.util.AttributeSet;
8+
import android.util.Log;
89
import android.view.ViewGroup;
910
import android.view.animation.AccelerateDecelerateInterpolator;
1011
import android.widget.FrameLayout;
@@ -107,22 +108,21 @@ public void onPreviewFrame(byte[] data, Camera camera) {
107108
int top;
108109
int rowWidth = size.width;
109110
int rowHeight = size.height;
110-
resolutionAdapter.setCameraSize(rowWidth, rowHeight);
111111
// 这里需要把得到的数据也翻转
112-
if (CameraUtil.isPortrait(getContext())) {
112+
boolean portrait = CameraUtil.isPortrait(getContext());
113+
if (portrait) {
113114
left = scanBoxRect.top - expandTop;
114115
top = scanBoxRect.left;
115116
} else {
116117
left = scanBoxRect.left;
117-
top = scanBoxRect.top - expandTop;
118+
top = scanBoxRect.top;
118119
}
119120

121+
resolutionAdapter.setCameraSize(portrait, rowWidth, rowHeight);
120122
left = resolutionAdapter.getAdapterWidth(left);
121123
top = resolutionAdapter.getAdapterHeight(top);
122124
scanBoxSize = resolutionAdapter.getAdapterWidth(scanBoxSize);
123-
124125
scanDataStrategy(data, left, top, scanBoxSize, scanBoxSize, rowWidth, rowHeight);
125-
126126
} catch (Exception e) {
127127
e.printStackTrace();
128128
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ private void calFramingRect() {
200200

201201
int viewWidth = getWidth();
202202
int viewHeight = getHeight();
203-
mBoxSize = Math.min(viewWidth * 3 / 5, MAX_BOX_SIZE);
203+
int minSize = Math.min(viewHeight, viewWidth);
204+
mBoxSize = Math.min(minSize * 3 / 5, MAX_BOX_SIZE);
204205
mBoxLeft = (viewWidth - mBoxSize) / 2;
205206
mBoxTop = (viewHeight - mBoxSize) / 2 + mTopOffset;
206207
mFramingRect = new Rect(mBoxLeft, mBoxTop, mBoxLeft + mBoxSize, mBoxTop + mBoxSize);

sample/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ android {
4848
dependencies {
4949

5050
// implementation project(':czxing')
51-
implementation 'me.devilsen:CZXing:0.8.7'
51+
implementation 'me.devilsen:CZXing:0.8.8'
5252

5353
implementation rootProject.ext.appcompat
5454
testImplementation rootProject.ext.junit

0 commit comments

Comments
 (0)