mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-06-27 09:02:59 +02:00
pass rotated resolution to ImageCaptureUsecase
- filter supported resolutions so 0MP resolutions are not selected. CameraX cannot apply these resolutions
This commit is contained in:
@ -5,6 +5,7 @@ import android.content.Context
|
||||
import android.hardware.SensorManager
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.util.Log
|
||||
import android.util.Size
|
||||
import android.view.*
|
||||
import android.view.GestureDetector.SimpleOnGestureListener
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
@ -74,7 +75,7 @@ class CameraXPreview(
|
||||
in 225 until 315 -> Surface.ROTATION_90
|
||||
else -> Surface.ROTATION_0
|
||||
}
|
||||
|
||||
Log.i(TAG, "onOrientationChanged: rotation=$rotation")
|
||||
preview?.targetRotation = rotation
|
||||
imageCapture?.targetRotation = rotation
|
||||
videoCapture?.targetRotation = rotation
|
||||
@ -194,13 +195,24 @@ class CameraXPreview(
|
||||
.setTargetRotation(rotation)
|
||||
.apply {
|
||||
imageQualityManager.getUserSelectedResolution(cameraSelector)?.let { resolution ->
|
||||
val rotatedResolution = getRotatedResolution(rotation, resolution)
|
||||
Log.i(TAG, "buildImageCapture: rotation=$rotation")
|
||||
Log.i(TAG, "buildImageCapture: resolution=$resolution")
|
||||
setTargetResolution(resolution)
|
||||
Log.i(TAG, "buildImageCapture: rotatedResolution=$rotatedResolution")
|
||||
setTargetResolution(rotatedResolution)
|
||||
} ?: setTargetAspectRatio(aspectRatio)
|
||||
}
|
||||
.build()
|
||||
}
|
||||
|
||||
private fun getRotatedResolution(rotationDegrees: Int, resolution: Size): Size {
|
||||
return if (rotationDegrees == Surface.ROTATION_0 || rotationDegrees == Surface.ROTATION_180) {
|
||||
Size(resolution.height, resolution.width)
|
||||
} else {
|
||||
Size(resolution.width, resolution.height)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildPreview(aspectRatio: Int, rotation: Int): Preview {
|
||||
return Preview.Builder()
|
||||
.setTargetRotation(rotation)
|
||||
|
Reference in New Issue
Block a user