Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions android/src/main/java/com/rncamerakit/CKCamera.kt
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,13 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs

private fun bindCameraUseCases() {
if (viewFinder.display == null) return
// Get screen metrics used to setup camera for full screen resolution
val metrics = DisplayMetrics().also { viewFinder.display.getRealMetrics(it) }
Log.d(TAG, "Screen metrics: ${metrics.widthPixels} x ${metrics.heightPixels}")

val screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)
Log.d(TAG, "Preview aspect ratio: $screenAspectRatio")
val previewWidth = viewFinder.getWidth();
val previewHeight = viewFinder.getHeight();
Log.d(TAG, "Preview dimensions: $previewWidth x $previewHeight")

val previewAspectRatio = aspectRatio(previewWidth, previewHeight)
Log.d(TAG, "Preview aspect ratio: $previewAspectRatio")

val rotation = viewFinder.display.rotation

Expand All @@ -301,7 +302,7 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs
// Preview
preview = Preview.Builder()
// We request aspect ratio but no resolution
.setTargetAspectRatio(screenAspectRatio)
.setTargetAspectRatio(previewAspectRatio)
// Set initial target rotation
.setTargetRotation(rotation)
.build()
Expand All @@ -311,7 +312,7 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
// We request aspect ratio but no resolution to match preview config, but letting
// CameraX optimize for whatever specific resolution best fits our use cases
.setTargetAspectRatio(screenAspectRatio)
.setTargetAspectRatio(previewAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
.setTargetRotation(rotation)
Expand All @@ -320,7 +321,7 @@ class CKCamera(context: ThemedReactContext) : FrameLayout(context), LifecycleObs
// ImageAnalysis
imageAnalyzer = ImageAnalysis.Builder()
.setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
.setTargetAspectRatio(screenAspectRatio)
.setTargetAspectRatio(previewAspectRatio)
.build()

val useCases = mutableListOf(preview, imageCapture)
Expand Down
Loading