react-native-rectangle-doc-scanner 7.39.0 → 7.40.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.
|
@@ -559,33 +559,42 @@ class CameraController(
|
|
|
559
559
|
val viewHeight = previewView.height.toFloat()
|
|
560
560
|
val preview = previewSize ?: return
|
|
561
561
|
if (viewWidth == 0f || viewHeight == 0f) return
|
|
562
|
+
|
|
562
563
|
val rotation = previewView.display?.rotation ?: Surface.ROTATION_0
|
|
564
|
+
val rotationDegrees = when (rotation) {
|
|
565
|
+
Surface.ROTATION_0 -> 0
|
|
566
|
+
Surface.ROTATION_90 -> 90
|
|
567
|
+
Surface.ROTATION_180 -> 180
|
|
568
|
+
Surface.ROTATION_270 -> 270
|
|
569
|
+
else -> 0
|
|
570
|
+
}
|
|
563
571
|
Log.d(
|
|
564
572
|
TAG,
|
|
565
|
-
"[TRANSFORM] rotation=$
|
|
573
|
+
"[TRANSFORM] rotation=$rotationDegrees view=${viewWidth}x${viewHeight} preview=${preview.width}x${preview.height}"
|
|
566
574
|
)
|
|
567
575
|
|
|
568
|
-
val
|
|
569
|
-
val bufferWidth = preview.width.toFloat()
|
|
570
|
-
val bufferHeight = preview.height.toFloat()
|
|
571
|
-
val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
|
|
572
|
-
|
|
576
|
+
val matrix = Matrix()
|
|
573
577
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
574
|
-
val bufferRect = if (
|
|
575
|
-
RectF(0f, 0f,
|
|
578
|
+
val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
579
|
+
RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
|
|
576
580
|
} else {
|
|
577
|
-
RectF(0f, 0f,
|
|
581
|
+
RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
578
582
|
}
|
|
579
583
|
val centerX = viewRect.centerX()
|
|
580
584
|
val centerY = viewRect.centerY()
|
|
581
|
-
val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
|
|
582
585
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
+
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
587
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
588
|
+
val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
|
|
586
589
|
matrix.postScale(scale, scale, centerX, centerY)
|
|
587
|
-
|
|
588
|
-
|
|
590
|
+
|
|
591
|
+
when (rotation) {
|
|
592
|
+
Surface.ROTATION_90, Surface.ROTATION_270 -> {
|
|
593
|
+
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
594
|
+
}
|
|
595
|
+
Surface.ROTATION_180 -> {
|
|
596
|
+
matrix.postRotate(180f, centerX, centerY)
|
|
597
|
+
}
|
|
589
598
|
}
|
|
590
599
|
|
|
591
600
|
previewView.setTransform(matrix)
|