react-native-rectangle-doc-scanner 7.39.0 → 7.41.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,33 +559,41 @@ 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
|
|
569
|
-
val bufferWidth = preview.width.toFloat()
|
|
570
|
-
val bufferHeight = preview.height.toFloat()
|
|
571
|
-
val isSwapped = rotationDegrees == 90 || rotationDegrees == 270
|
|
572
|
-
|
|
576
|
+
val matrix = Matrix()
|
|
573
577
|
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
574
|
-
val bufferRect =
|
|
575
|
-
RectF(0f, 0f, bufferHeight, bufferWidth)
|
|
576
|
-
} else {
|
|
577
|
-
RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
578
|
-
}
|
|
578
|
+
val bufferRect = RectF(0f, 0f, preview.width.toFloat(), preview.height.toFloat())
|
|
579
579
|
val centerX = viewRect.centerX()
|
|
580
580
|
val centerY = viewRect.centerY()
|
|
581
|
-
val scale = max(viewWidth / bufferRect.width(), viewHeight / bufferRect.height())
|
|
582
581
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
matrix.
|
|
582
|
+
if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) {
|
|
583
|
+
val swappedBufferRect = RectF(0f, 0f, preview.height.toFloat(), preview.width.toFloat())
|
|
584
|
+
swappedBufferRect.offset(centerX - swappedBufferRect.centerX(), centerY - swappedBufferRect.centerY())
|
|
585
|
+
matrix.setRectToRect(viewRect, swappedBufferRect, Matrix.ScaleToFit.FILL)
|
|
586
|
+
val scale = max(viewHeight / preview.height.toFloat(), viewWidth / preview.width.toFloat())
|
|
587
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
588
|
+
matrix.postRotate(90f * (rotation - 2), centerX, centerY)
|
|
589
|
+
} else if (rotation == Surface.ROTATION_180) {
|
|
590
|
+
matrix.postRotate(180f, centerX, centerY)
|
|
591
|
+
} else {
|
|
592
|
+
val scale = max(viewWidth / preview.width.toFloat(), viewHeight / preview.height.toFloat())
|
|
593
|
+
val scaledWidth = preview.width.toFloat() * scale
|
|
594
|
+
val scaledHeight = preview.height.toFloat() * scale
|
|
595
|
+
matrix.setScale(scale, scale)
|
|
596
|
+
matrix.postTranslate((viewWidth - scaledWidth) / 2f, (viewHeight - scaledHeight) / 2f)
|
|
589
597
|
}
|
|
590
598
|
|
|
591
599
|
previewView.setTransform(matrix)
|