react-native-rectangle-doc-scanner 7.38.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,29 +559,43 @@ 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 rotationDegrees = displayRotationDegrees()
|
|
569
|
-
val bufferWidth = preview.width.toFloat()
|
|
570
|
-
val bufferHeight = preview.height.toFloat()
|
|
571
|
-
val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
|
|
572
|
-
val rotatedWidth = if (isSwapped) bufferHeight else bufferWidth
|
|
573
|
-
val rotatedHeight = if (isSwapped) bufferWidth else bufferHeight
|
|
574
|
-
val scale = max(viewWidth / rotatedWidth, viewHeight / rotatedHeight)
|
|
575
|
-
val rotateDegrees = -rotationDegrees.toFloat()
|
|
576
|
-
|
|
577
|
-
// Rotate around buffer center, then scale uniformly and center in the view (aspect-fill).
|
|
578
576
|
val matrix = Matrix()
|
|
579
|
-
|
|
580
|
-
if (
|
|
581
|
-
|
|
577
|
+
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
578
|
+
val bufferRect = if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
579
|
+
RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
|
|
580
|
+
} else {
|
|
581
|
+
RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
582
|
+
}
|
|
583
|
+
val centerX = viewRect.centerX()
|
|
584
|
+
val centerY = viewRect.centerY()
|
|
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())
|
|
589
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
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
|
+
}
|
|
582
598
|
}
|
|
583
|
-
matrix.postScale(scale, scale)
|
|
584
|
-
matrix.postTranslate(viewWidth / 2f, viewHeight / 2f)
|
|
585
599
|
|
|
586
600
|
previewView.setTransform(matrix)
|
|
587
601
|
Log.d(TAG, "[TRANSFORM] Matrix applied successfully")
|