react-native-rectangle-doc-scanner 3.217.0 → 3.219.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -157,34 +157,57 @@ class CameraController(
|
|
|
157
157
|
|
|
158
158
|
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
159
159
|
|
|
160
|
-
// Build Preview
|
|
160
|
+
// Build Preview ONLY first
|
|
161
161
|
preview = Preview.Builder()
|
|
162
|
-
.
|
|
162
|
+
.setTargetResolution(Size(1280, 720))
|
|
163
163
|
.setTargetRotation(rotation)
|
|
164
164
|
.build()
|
|
165
165
|
.also {
|
|
166
166
|
it.setSurfaceProvider(previewView.surfaceProvider)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
// Build ImageAnalysis
|
|
170
|
-
imageAnalysis = ImageAnalysis.Builder()
|
|
171
|
-
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
172
|
-
.setTargetRotation(rotation)
|
|
173
|
-
.setTargetAspectRatio(AspectRatio.RATIO_4_3)
|
|
174
|
-
.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
|
|
175
|
-
.build()
|
|
176
|
-
.also {
|
|
177
|
-
it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
|
|
178
|
-
}
|
|
179
|
-
|
|
180
169
|
val cameraSelector = if (useFrontCamera) {
|
|
181
170
|
CameraSelector.DEFAULT_FRONT_CAMERA
|
|
182
171
|
} else {
|
|
183
172
|
CameraSelector.DEFAULT_BACK_CAMERA
|
|
184
173
|
}
|
|
185
174
|
|
|
186
|
-
// Bind
|
|
175
|
+
// Step 1: Bind Preview ONLY first
|
|
176
|
+
try {
|
|
177
|
+
camera = provider.bindToLifecycle(
|
|
178
|
+
lifecycleOwner,
|
|
179
|
+
cameraSelector,
|
|
180
|
+
preview
|
|
181
|
+
)
|
|
182
|
+
Log.d(TAG, "[CAMERAX-FIX-V4] Preview bound, waiting before adding analysis...")
|
|
183
|
+
|
|
184
|
+
// Step 2: Add ImageAnalysis after a delay to let Preview session stabilize
|
|
185
|
+
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
|
186
|
+
bindImageAnalysis(provider, cameraSelector, rotation)
|
|
187
|
+
}, 500)
|
|
188
|
+
|
|
189
|
+
} catch (e: Exception) {
|
|
190
|
+
Log.e(TAG, "[CAMERAX-FIX-V4] Failed to bind preview", e)
|
|
191
|
+
analysisBound = false
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
private fun bindImageAnalysis(provider: ProcessCameraProvider, cameraSelector: CameraSelector, rotation: Int) {
|
|
196
|
+
if (analysisBound) return
|
|
197
|
+
|
|
187
198
|
try {
|
|
199
|
+
// Build ImageAnalysis
|
|
200
|
+
imageAnalysis = ImageAnalysis.Builder()
|
|
201
|
+
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
|
|
202
|
+
.setTargetRotation(rotation)
|
|
203
|
+
.setTargetResolution(Size(640, 480))
|
|
204
|
+
.setOutputImageFormat(ImageAnalysis.OUTPUT_IMAGE_FORMAT_YUV_420_888)
|
|
205
|
+
.build()
|
|
206
|
+
.also {
|
|
207
|
+
it.setAnalyzer(cameraExecutor, DocumentAnalyzer())
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Rebind with both Preview and ImageAnalysis
|
|
188
211
|
camera = provider.bindToLifecycle(
|
|
189
212
|
lifecycleOwner,
|
|
190
213
|
cameraSelector,
|
|
@@ -192,9 +215,9 @@ class CameraController(
|
|
|
192
215
|
imageAnalysis
|
|
193
216
|
)
|
|
194
217
|
analysisBound = true
|
|
195
|
-
Log.d(TAG, "[CAMERAX-FIX-
|
|
218
|
+
Log.d(TAG, "[CAMERAX-FIX-V4] ImageAnalysis added successfully")
|
|
196
219
|
} catch (e: Exception) {
|
|
197
|
-
Log.e(TAG, "[CAMERAX-FIX-
|
|
220
|
+
Log.e(TAG, "[CAMERAX-FIX-V4] Failed to add ImageAnalysis", e)
|
|
198
221
|
analysisBound = false
|
|
199
222
|
}
|
|
200
223
|
}
|
package/package.json
CHANGED