react-native-rectangle-doc-scanner 7.20.0 → 7.22.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.Matrix
|
|
9
9
|
import android.graphics.SurfaceTexture
|
|
10
10
|
import android.graphics.Rect
|
|
11
|
+
import android.graphics.RectF
|
|
11
12
|
import android.graphics.ImageFormat
|
|
12
13
|
import android.hardware.camera2.CameraCaptureSession
|
|
13
14
|
import android.hardware.camera2.CameraCharacteristics
|
|
@@ -554,25 +555,39 @@ class CameraController(
|
|
|
554
555
|
val viewHeight = previewView.height.toFloat()
|
|
555
556
|
val preview = previewSize ?: return
|
|
556
557
|
if (viewWidth == 0f || viewHeight == 0f) return
|
|
557
|
-
val
|
|
558
|
-
Log.d(
|
|
558
|
+
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
559
|
+
Log.d(
|
|
560
|
+
TAG,
|
|
561
|
+
"[TRANSFORM] rotation=${displayRotationDegrees()} view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
|
|
562
|
+
)
|
|
559
563
|
|
|
560
564
|
val matrix = Matrix()
|
|
561
|
-
val
|
|
562
|
-
val
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
val
|
|
568
|
-
val
|
|
569
|
-
val dx = (viewWidth - scaledWidth) / 2f
|
|
570
|
-
val dy = (viewHeight - scaledHeight) / 2f
|
|
571
|
-
matrix.setScale(scale, scale)
|
|
572
|
-
matrix.postTranslate(dx, dy)
|
|
565
|
+
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
566
|
+
val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
567
|
+
RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
|
|
568
|
+
} else {
|
|
569
|
+
RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
570
|
+
}
|
|
571
|
+
val centerX = viewRect.centerX()
|
|
572
|
+
val centerY = viewRect.centerY()
|
|
573
573
|
|
|
574
|
-
if (
|
|
575
|
-
|
|
574
|
+
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
575
|
+
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
576
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
577
|
+
val scale = max(
|
|
578
|
+
viewHeight / preview.height.toFloat(),
|
|
579
|
+
viewWidth / preview.width.toFloat()
|
|
580
|
+
)
|
|
581
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
582
|
+
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
583
|
+
} else if (rotation == Surface.ROTATION_180) {
|
|
584
|
+
matrix.postRotate(180f, centerX, centerY)
|
|
585
|
+
} else {
|
|
586
|
+
val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
|
|
587
|
+
val scaledWidth = preview.width.toFloat() * scale
|
|
588
|
+
val scaledHeight = preview.height.toFloat() * scale
|
|
589
|
+
matrix.setScale(scale, scale)
|
|
590
|
+
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
576
591
|
}
|
|
577
592
|
|
|
578
593
|
previewView.setTransform(matrix)
|