Fix AndroidUSBCamera squeezed/distorted image scaling

This commit is contained in:
Jannik committed 2026-08-25 17:21:10 +02:00
1 parent 203dd19a08
commit f34eaf7235
6 files changed
+29 -10

No files matched your search

@@ -149,11 +149,27 @@ class UsbCameraView(context: Context, appContext: AppContext) : ExpoView(context
val viewH = (bottom - top).toFloat()
if (viewW > 0 && viewH > 0 && parentW > 0 && parentH > 0) {
val scaleX = parentW / viewW
val scaleY = parentH / viewH
val maxScale = kotlin.math.max(scaleX, scaleY)
v.scaleX = maxScale
v.scaleY = maxScale
// The camera stream is 1920x1080 (16:9).
val cameraAspectRatio = 1920f / 1080f
// Calculate the target dimensions to maintain the camera aspect ratio
// while completely covering the parent (Center Crop).
var targetW = parentH * cameraAspectRatio
var targetH = parentH
if (targetW < parentW) {
targetW = parentW
targetH = parentW / cameraAspectRatio
}
// If the texture view was forced to match parent by layout manager,
// it might be distorted. The independent scaleX and scaleY factors
// will simultaneously fix any distortion and apply the crop.
val scaleX = targetW / viewW
val scaleY = targetH / viewH
v.scaleX = scaleX
v.scaleY = scaleY
}
}
try {