react-native-rectangle-doc-scanner 13.1.0 → 13.2.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.
|
@@ -494,10 +494,10 @@ class CameraController(
|
|
|
494
494
|
val finalWidth = imageWidth
|
|
495
495
|
val finalHeight = imageHeight
|
|
496
496
|
|
|
497
|
-
// Apply
|
|
497
|
+
// Apply center-crop scaling to match TextureView display.
|
|
498
498
|
val scaleX = viewWidth / finalWidth.toFloat()
|
|
499
499
|
val scaleY = viewHeight / finalHeight.toFloat()
|
|
500
|
-
val scale = scaleX.
|
|
500
|
+
val scale = scaleX.coerceAtLeast(scaleY)
|
|
501
501
|
|
|
502
502
|
val scaledWidth = finalWidth * scale
|
|
503
503
|
val scaledHeight = finalHeight * scale
|
|
@@ -583,26 +583,17 @@ class CameraController(
|
|
|
583
583
|
bufferHeight
|
|
584
584
|
}
|
|
585
585
|
|
|
586
|
-
// Scale to
|
|
586
|
+
// Scale to fill the view while maintaining aspect ratio (center-crop)
|
|
587
587
|
val scaleX = viewWidth.toFloat() / rotatedBufferWidth.toFloat()
|
|
588
588
|
val scaleY = viewHeight.toFloat() / rotatedBufferHeight.toFloat()
|
|
589
|
-
val scale = scaleX.
|
|
589
|
+
val scale = scaleX.coerceAtLeast(scaleY) // Use max to fill
|
|
590
590
|
|
|
591
591
|
Log.d(TAG, "[TRANSFORM] Rotated buffer: ${rotatedBufferWidth}x${rotatedBufferHeight}, ScaleX: $scaleX, ScaleY: $scaleY, Using: $scale")
|
|
592
592
|
|
|
593
593
|
matrix.postScale(scale, scale, centerX, centerY)
|
|
594
594
|
|
|
595
|
-
//
|
|
596
|
-
|
|
597
|
-
val scaledHeight = rotatedBufferHeight * scale
|
|
598
|
-
val offsetX = (viewWidth - scaledWidth) / 2f
|
|
599
|
-
val offsetY = (viewHeight - scaledHeight) / 2f
|
|
600
|
-
previewViewport = android.graphics.RectF(
|
|
601
|
-
offsetX,
|
|
602
|
-
offsetY,
|
|
603
|
-
offsetX + scaledWidth,
|
|
604
|
-
offsetY + scaledHeight
|
|
605
|
-
)
|
|
595
|
+
// With center-crop, the preview fully covers the view bounds.
|
|
596
|
+
previewViewport = android.graphics.RectF(0f, 0f, viewWidth.toFloat(), viewHeight.toFloat())
|
|
606
597
|
|
|
607
598
|
textureView.setTransform(matrix)
|
|
608
599
|
Log.d(TAG, "[TRANSFORM] Transform applied successfully")
|
package/android/src/camera2/kotlin/com/reactnativerectangledocscanner/DocumentScannerView.kt
CHANGED
|
@@ -150,19 +150,13 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
150
150
|
private fun layoutPreviewAndOverlay(viewWidth: Int, viewHeight: Int) {
|
|
151
151
|
if (viewWidth <= 0 || viewHeight <= 0) return
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
val
|
|
155
|
-
val
|
|
156
|
-
if (aspectHeight <= viewHeight) {
|
|
157
|
-
targetWidth = viewWidth
|
|
158
|
-
targetHeight = aspectHeight
|
|
159
|
-
} else {
|
|
160
|
-
targetWidth = (viewHeight * PREVIEW_ASPECT_RATIO).toInt()
|
|
161
|
-
targetHeight = viewHeight
|
|
162
|
-
}
|
|
153
|
+
// Always fill width to avoid left/right letterboxing.
|
|
154
|
+
val targetWidth = viewWidth
|
|
155
|
+
val targetHeight = (viewWidth / PREVIEW_ASPECT_RATIO).toInt()
|
|
163
156
|
|
|
164
|
-
val left =
|
|
165
|
-
|
|
157
|
+
val left = 0
|
|
158
|
+
// Center vertically; allows top/bottom crop when targetHeight > viewHeight.
|
|
159
|
+
val top = (viewHeight - targetHeight) / 2
|
|
166
160
|
val right = left + targetWidth
|
|
167
161
|
val bottom = top + targetHeight
|
|
168
162
|
|