react-native-rectangle-doc-scanner 7.22.0 → 7.23.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.
|
@@ -562,32 +562,27 @@ class CameraController(
|
|
|
562
562
|
)
|
|
563
563
|
|
|
564
564
|
val matrix = Matrix()
|
|
565
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
566
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
567
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
565
568
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
566
|
-
val bufferRect =
|
|
567
|
-
RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
|
|
568
|
-
} else {
|
|
569
|
-
RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
570
|
-
}
|
|
569
|
+
val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
571
570
|
val centerX = viewRect.centerX()
|
|
572
571
|
val centerY = viewRect.centerY()
|
|
573
572
|
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
)
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
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)
|
|
573
|
+
// Preserve aspect ratio, then scale to fill (center-crop) without distortion.
|
|
574
|
+
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
|
|
575
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
576
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
577
|
+
|
|
578
|
+
if (rotation != Surface.ROTATION_0) {
|
|
579
|
+
val rotateDegrees = when (rotation) {
|
|
580
|
+
Surface.ROTATION_90 -> -90f
|
|
581
|
+
Surface.ROTATION_180 -> 180f
|
|
582
|
+
Surface.ROTATION_270 -> 90f
|
|
583
|
+
else -> 0f
|
|
584
|
+
}
|
|
585
|
+
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
591
586
|
}
|
|
592
587
|
|
|
593
588
|
previewView.setTransform(matrix)
|