mirror of
https://github.com/SimpleMobileTools/Simple-Camera.git
synced 2025-02-18 12:20:36 +01:00
add a toggle for selecting if front/rear camera should be used
This commit is contained in:
parent
3d7ec35e3b
commit
d01ad834f6
@ -42,6 +42,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
private var mIsFlashSupported = true
|
private var mIsFlashSupported = true
|
||||||
private var mIsImageCaptureIntent = false
|
private var mIsImageCaptureIntent = false
|
||||||
private var mIsInVideoMode = false
|
private var mIsInVideoMode = false
|
||||||
|
private var mUseFrontCamera = false
|
||||||
private var mCameraId = ""
|
private var mCameraId = ""
|
||||||
private var mCameraState = STATE_INIT
|
private var mCameraState = STATE_INIT
|
||||||
private var mFlashlightState = FLASH_OFF
|
private var mFlashlightState = FLASH_OFF
|
||||||
@ -111,7 +112,7 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun openCamera(width: Int, height: Int) {
|
private fun openCamera(width: Int, height: Int) {
|
||||||
setUpCameraOutputs(width, height)
|
setupCameraOutputs(width, height)
|
||||||
configureTransform(width, height)
|
configureTransform(width, height)
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||||
try {
|
try {
|
||||||
@ -124,14 +125,22 @@ class PreviewCameraTwo : ViewGroup, TextureView.SurfaceTextureListener, MyPrevie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val imageAvailableListener = ImageReader.OnImageAvailableListener { reader -> val image = reader.acquireNextImage() }
|
private val imageAvailableListener = ImageReader.OnImageAvailableListener { reader ->
|
||||||
|
val image = reader.acquireNextImage()
|
||||||
|
val buffer = image.planes[0].buffer
|
||||||
|
}
|
||||||
|
|
||||||
private fun setUpCameraOutputs(width: Int, height: Int) {
|
private fun setupCameraOutputs(width: Int, height: Int) {
|
||||||
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
val manager = mActivity.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
||||||
try {
|
try {
|
||||||
for (cameraId in manager.cameraIdList) {
|
for (cameraId in manager.cameraIdList) {
|
||||||
val characteristics = manager.getCameraCharacteristics(cameraId)
|
val characteristics = manager.getCameraCharacteristics(cameraId)
|
||||||
|
|
||||||
|
val facing = characteristics.get(CameraCharacteristics.LENS_FACING) ?: continue
|
||||||
|
if ((mUseFrontCamera && facing == CameraCharacteristics.LENS_FACING_BACK) || !mUseFrontCamera && facing == CameraCharacteristics.LENS_FACING_FRONT) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
val map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) ?: continue
|
val map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) ?: continue
|
||||||
val largest = map.getOutputSizes(ImageFormat.JPEG).maxBy { it.width * it.height }
|
val largest = map.getOutputSizes(ImageFormat.JPEG).maxBy { it.width * it.height }
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user