react-native-rectangle-doc-scanner 3.195.0 → 3.196.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.
|
@@ -8,6 +8,7 @@ import android.graphics.BitmapFactory
|
|
|
8
8
|
import android.graphics.ImageFormat
|
|
9
9
|
import android.graphics.Matrix
|
|
10
10
|
import android.graphics.Rect
|
|
11
|
+
import android.graphics.RectF
|
|
11
12
|
import android.graphics.SurfaceTexture
|
|
12
13
|
import android.graphics.YuvImage
|
|
13
14
|
import android.hardware.camera2.CameraCaptureSession
|
|
@@ -80,6 +81,7 @@ class CameraController(
|
|
|
80
81
|
|
|
81
82
|
override fun onSurfaceTextureSizeChanged(surface: SurfaceTexture, width: Int, height: Int) {
|
|
82
83
|
Log.d(TAG, "[CAMERA2] Texture size changed: ${width}x${height}")
|
|
84
|
+
updatePreviewTransform()
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture): Boolean {
|
|
@@ -330,6 +332,7 @@ class CameraController(
|
|
|
330
332
|
try {
|
|
331
333
|
session.setRepeatingRequest(previewRequestBuilder!!.build(), null, backgroundHandler)
|
|
332
334
|
Log.d(TAG, "[CAMERA2] Preview session started")
|
|
335
|
+
updatePreviewTransform()
|
|
333
336
|
} catch (e: Exception) {
|
|
334
337
|
Log.e(TAG, "[CAMERA2] Failed to start preview", e)
|
|
335
338
|
}
|
|
@@ -346,6 +349,44 @@ class CameraController(
|
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
351
|
|
|
352
|
+
private fun updatePreviewTransform() {
|
|
353
|
+
val previewSize = previewSize ?: return
|
|
354
|
+
val viewWidth = previewView.width
|
|
355
|
+
val viewHeight = previewView.height
|
|
356
|
+
if (viewWidth == 0 || viewHeight == 0) {
|
|
357
|
+
return
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
361
|
+
val matrix = Matrix()
|
|
362
|
+
val viewRect = RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
|
|
363
|
+
val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
364
|
+
RectF(0f, 0f, previewSize.height.toFloat(), previewSize.width.toFloat())
|
|
365
|
+
} else {
|
|
366
|
+
RectF(0f, 0f, previewSize.width.toFloat(), previewSize.height.toFloat())
|
|
367
|
+
}
|
|
368
|
+
val centerX = viewRect.centerX()
|
|
369
|
+
val centerY = viewRect.centerY()
|
|
370
|
+
|
|
371
|
+
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
372
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
373
|
+
|
|
374
|
+
val scale = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
375
|
+
maxOf(viewHeight.toFloat() / previewSize.height, viewWidth.toFloat() / previewSize.width)
|
|
376
|
+
} else {
|
|
377
|
+
maxOf(viewWidth.toFloat() / previewSize.width, viewHeight.toFloat() / previewSize.height)
|
|
378
|
+
}
|
|
379
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
380
|
+
|
|
381
|
+
when (rotation) {
|
|
382
|
+
Surface.ROTATION_90 -> matrix.postRotate(90f, centerX, centerY)
|
|
383
|
+
Surface.ROTATION_180 -> matrix.postRotate(180f, centerX, centerY)
|
|
384
|
+
Surface.ROTATION_270 -> matrix.postRotate(270f, centerX, centerY)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
previewView.setTransform(matrix)
|
|
388
|
+
}
|
|
389
|
+
|
|
349
390
|
private fun handleImage(image: Image) {
|
|
350
391
|
try {
|
|
351
392
|
val rotationDegrees = getRotationDegrees()
|
package/package.json
CHANGED