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

+2 -2
View File
@@ -92,8 +92,8 @@ android {
applicationId 'de.orfel.schnappix'
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 70
versionName "23.01.70"
versionCode 71
versionName "23.01.71"
buildConfigField "String", "REACT_NATIVE_RELEASE_LEVEL", "\"${findProperty('reactNativeReleaseLevel') ?: 'stable'}\""
}
Binary file not shown.
Binary file not shown.
+2 -2
View File
@@ -3,7 +3,7 @@
"newArchEnabled": true,
"name": "Schnappix",
"slug": "Schnappix",
"version": "23.01.70",
"version": "23.01.71",
"orientation": "landscape",
"icon": "./Icon.png",
"userInterfaceStyle": "dark",
@@ -13,7 +13,7 @@
},
"android": {
"package": "de.orfel.schnappix",
"versionCode": 70,
"versionCode": 71,
"usesCleartextTraffic": true,
"adaptiveIcon": {
"backgroundColor": "#050510",
@@ -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 {
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "schnappix",
"version": "23.01.70",
"version": "23.01.71",
"main": "index.ts",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.7.2",