Skip to content

Commit

Permalink
setTargetResolution instead of setTargetAspectRatio
Browse files Browse the repository at this point in the history
  • Loading branch information
hongbeomi committed Dec 20, 2020
1 parent e116dc9 commit b7942f4
Showing 1 changed file with 2 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github.hongbeomi.macgyver.camerax
import android.content.Context
import android.util.DisplayMetrics
import android.util.Log
import android.util.Size
import android.view.ScaleGestureDetector
import androidx.camera.core.*
import androidx.camera.lifecycle.ProcessCameraProvider
Expand Down Expand Up @@ -31,7 +32,6 @@ class CameraManager(
private var camera: Camera? = null
private var cameraProvider: ProcessCameraProvider? = null
private var imageAnalyzer: ImageAnalysis? = null
private var screenAspectRatio: Int? = null

// default barcode scanner
private var analyzerVisionType: VisionType = VisionType.Barcode
Expand Down Expand Up @@ -99,14 +99,6 @@ class CameraManager(
}
}

private fun aspectRatio(width: Int, height: Int): Int {
val previewRatio = max(width, height).toDouble() / min(width, height)
if (abs(previewRatio - RATIO_4_3_VALUE) <= abs(previewRatio - RATIO_16_9_VALUE)) {
return AspectRatio.RATIO_4_3
}
return AspectRatio.RATIO_16_9
}

fun startCamera() {
val cameraProviderFuture = ProcessCameraProvider.getInstance(context)
cameraProviderFuture.addListener(
Expand All @@ -126,12 +118,10 @@ class CameraManager(
.build()

metrics = DisplayMetrics().also { finderView.display.getRealMetrics(it) }
screenAspectRatio = aspectRatio(metrics.widthPixels, metrics.heightPixels)

imageCapture =
ImageCapture.Builder()
.setCaptureMode(ImageCapture.CAPTURE_MODE_MINIMIZE_LATENCY)
.setTargetAspectRatio(screenAspectRatio!!)
.setTargetResolution(Size(metrics.widthPixels, metrics.heightPixels))
.build()

setUpPinchToZoom()
Expand Down

1 comment on commit b7942f4

@hongbeomi
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#4 resolve

Please sign in to comment.