react-native-rectangle-doc-scanner 7.47.0 → 7.48.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.
|
@@ -575,50 +575,23 @@ class CameraController(
|
|
|
575
575
|
|
|
576
576
|
val matrix = Matrix()
|
|
577
577
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
578
|
-
val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
579
578
|
val centerX = viewRect.centerX()
|
|
580
579
|
val centerY = viewRect.centerY()
|
|
581
580
|
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
581
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
582
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
583
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
584
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
585
|
+
val scaledWidth = bufferWidth * scale
|
|
586
|
+
val scaledHeight = bufferHeight * scale
|
|
586
587
|
|
|
587
|
-
|
|
588
|
-
|
|
588
|
+
matrix.setScale(scale, scale)
|
|
589
|
+
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
589
590
|
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
val bufferRect = RectF(0f, 0f, bufferHeight, bufferWidth)
|
|
593
|
-
val viewTargetRect = RectF(0f, 0f, viewWidth, effectiveHeight)
|
|
594
|
-
|
|
595
|
-
// Calculate the center of viewTargetRect within the actual view
|
|
596
|
-
val targetCenterX = viewWidth / 2f
|
|
597
|
-
val targetCenterY = viewHeight / 2f
|
|
598
|
-
|
|
599
|
-
// Step 1: Map buffer rect to view target rect with CENTER mode (maintains aspect ratio)
|
|
600
|
-
matrix.setRectToRect(bufferRect, viewTargetRect, Matrix.ScaleToFit.CENTER)
|
|
601
|
-
|
|
602
|
-
// Step 2: Translate to center of actual view
|
|
603
|
-
val scaledBufferWidth = bufferWidth * (effectiveHeight / bufferHeight)
|
|
604
|
-
val scaledBufferHeight = effectiveHeight
|
|
605
|
-
matrix.postTranslate(
|
|
606
|
-
targetCenterX - scaledBufferWidth / 2f,
|
|
607
|
-
targetCenterY - scaledBufferHeight / 2f
|
|
608
|
-
)
|
|
609
|
-
|
|
610
|
-
// Step 3: Rotate around the center
|
|
611
|
-
matrix.postRotate(90f * (rotation - 2), targetCenterX, targetCenterY)
|
|
612
|
-
|
|
613
|
-
Log.d(TAG, "[TRANSFORM] Android: buffer=${bufferWidth}x${bufferHeight}, effectiveH=$effectiveHeight, target=${scaledBufferWidth}x${scaledBufferHeight}")
|
|
591
|
+
if (isSwapped) {
|
|
592
|
+
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
614
593
|
} else if (rotation == Surface.ROTATION_180) {
|
|
615
594
|
matrix.postRotate(180f, centerX, centerY)
|
|
616
|
-
} else {
|
|
617
|
-
val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
|
|
618
|
-
val scaledWidth = preview.width.toFloat() * scale
|
|
619
|
-
val scaledHeight = preview.height.toFloat() * scale
|
|
620
|
-
matrix.setScale(scale, scale)
|
|
621
|
-
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
622
595
|
}
|
|
623
596
|
|
|
624
597
|
previewView.setTransform(matrix)
|