Skip to content

Commit d0ea3d7

Browse files
committed
修复频繁打开扫码页面崩溃的问题
1 parent 5ac3246 commit d0ea3d7

3 files changed

Lines changed: 23 additions & 30 deletions

File tree

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 17
10-
versionName "0.9.2"
9+
versionCode 18
10+
versionName "0.9.3"
1111

1212
externalNativeBuild {
1313
cmake {

czxing/src/main/cpp/ImageScheduler.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#include <src/BinaryBitmap.h>
88
#include "ImageScheduler.h"
99
#include "JNIUtils.h"
10-
#include <thread>
11-
#include <chrono>
1210

1311
#define DEFAULT_MIN_LIGHT 70;
1412

@@ -40,12 +38,7 @@ void *prepareMethod(void *arg) {
4038
return nullptr;
4139
}
4240

43-
void releaseFrameData(FrameData &frameData) {
44-
delete &frameData;
45-
}
46-
4741
void ImageScheduler::prepare() {
48-
frameQueue.setReleaseHandle(releaseFrameData);
4942
pthread_create(&prepareThread, nullptr, prepareMethod, this);
5043
}
5144

@@ -60,7 +53,6 @@ void ImageScheduler::start() {
6053
}
6154

6255
if (isProcessing.load()) {
63-
std::this_thread::sleep_for(chrono::milliseconds(100));
6456
continue;
6557
}
6658

@@ -113,29 +105,30 @@ ImageScheduler::process(jbyte *bytes, int left, int top, int cropWidth, int crop
113105
* 预处理二进制数据
114106
*/
115107
void ImageScheduler::preTreatMat(const FrameData &frameData) {
116-
if (&frameData == nullptr) {
117-
return;
118-
}
119-
120-
LOGE("start preTreatMat...");
108+
try {
109+
LOGE("start preTreatMat...");
121110

122-
Mat src(frameData.rowHeight + frameData.rowHeight / 2,
123-
frameData.rowWidth, CV_8UC1,
124-
frameData.bytes);
111+
Mat src(frameData.rowHeight + frameData.rowHeight / 2,
112+
frameData.rowWidth, CV_8UC1,
113+
frameData.bytes);
125114

126-
Mat gray;
127-
cvtColor(src, gray, COLOR_YUV2GRAY_NV21);
115+
Mat gray;
116+
cvtColor(src, gray, COLOR_YUV2GRAY_NV21);
128117

129-
if (frameData.left != 0) {
130-
gray = gray(Rect(frameData.left, frameData.top, frameData.cropWidth, frameData.cropHeight));
131-
}
118+
if (frameData.left != 0) {
119+
gray = gray(
120+
Rect(frameData.left, frameData.top, frameData.cropWidth, frameData.cropHeight));
121+
}
132122

133-
// 分析亮度,如果亮度过低,不进行处理
134-
analysisBrightness(gray);
135-
if (cameraLight < 40) {
136-
return;
123+
// 分析亮度,如果亮度过低,不进行处理
124+
analysisBrightness(gray);
125+
if (cameraLight < 40) {
126+
return;
127+
}
128+
decodeGrayPixels(gray);
129+
} catch (const std::exception &e) {
130+
LOGE("preTreatMat error...");
137131
}
138-
decodeGrayPixels(gray);
139132
}
140133

141134
void ImageScheduler::decodeGrayPixels(const Mat &gray) {
@@ -280,7 +273,7 @@ Result ImageScheduler::decodePixels(Mat mat) {
280273
return Result(DecodeStatus::NotFound);
281274
}
282275

283-
bool ImageScheduler::analysisBrightness(const Mat& gray) {
276+
bool ImageScheduler::analysisBrightness(const Mat &gray) {
284277
LOGE("start analysisBrightness...");
285278

286279
// 平均亮度

sample/build.gradle

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

5050
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-beta-3'
5151
// implementation project(':czxing')
52-
implementation 'me.devilsen:CZXing:0.9.2'
52+
implementation 'me.devilsen:CZXing:0.9.3'
5353

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

0 commit comments

Comments
 (0)