react-native-rectangle-doc-scanner 7.22.0 → 7.24.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.
|
@@ -246,8 +246,10 @@ class CameraController(
|
|
|
246
246
|
val previewSizes = streamConfigMap.getOutputSizes(SurfaceTexture::class.java)
|
|
247
247
|
Log.d(TAG, "[CAMERA2] Available preview sizes: ${previewSizes?.take(10)?.joinToString { "${it.width}x${it.height}" }}")
|
|
248
248
|
|
|
249
|
-
//
|
|
250
|
-
|
|
249
|
+
// Match iOS photo preset behavior (4:3) when available for consistent FOV.
|
|
250
|
+
val targetPreviewAspect = 4.0 / 3.0
|
|
251
|
+
previewSize = chooseBestSize(previewSizes, targetPreviewAspect, null, preferClosestAspect = true)
|
|
252
|
+
?: chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
251
253
|
?: previewSizes?.maxByOrNull { it.width * it.height }
|
|
252
254
|
Log.d(TAG, "[CAMERA2] Selected preview size: ${previewSize?.width}x${previewSize?.height}")
|
|
253
255
|
|
|
@@ -562,32 +564,27 @@ class CameraController(
|
|
|
562
564
|
)
|
|
563
565
|
|
|
564
566
|
val matrix = Matrix()
|
|
567
|
+
val isSwapped = rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270
|
|
568
|
+
val bufferWidth = if (isSwapped) preview.height.toFloat() else preview.width.toFloat()
|
|
569
|
+
val bufferHeight = if (isSwapped) preview.width.toFloat() else preview.height.toFloat()
|
|
565
570
|
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
|
-
}
|
|
571
|
+
val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
571
572
|
val centerX = viewRect.centerX()
|
|
572
573
|
val centerY = viewRect.centerY()
|
|
573
574
|
|
|
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)
|
|
575
|
+
// Preserve aspect ratio, then scale to fill (center-crop) without distortion.
|
|
576
|
+
matrix.setRectToRect(bufferRect, viewRect, Matrix.ScaleToFit.CENTER)
|
|
577
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
578
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
579
|
+
|
|
580
|
+
if (rotation != Surface.ROTATION_0) {
|
|
581
|
+
val rotateDegrees = when (rotation) {
|
|
582
|
+
Surface.ROTATION_90 -> -90f
|
|
583
|
+
Surface.ROTATION_180 -> 180f
|
|
584
|
+
Surface.ROTATION_270 -> 90f
|
|
585
|
+
else -> 0f
|
|
586
|
+
}
|
|
587
|
+
matrix.postRotate(rotateDegrees, centerX, centerY)
|
|
591
588
|
}
|
|
592
589
|
|
|
593
590
|
previewView.setTransform(matrix)
|