Camera2
Cmaera2 is the android official package that makes developers being able to develop various camera characteristics in detail.
See more information => https://developer.android.com/media/camera/camera2
Prerequisite
You could see preview on your app( if not, this site will help you =>https://github.com/googlearchive/android-Camera2Basic/blob/master/kotlinApp/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.kt)
How to request changing camera params?
All of camera prams are changed by using CaptureRequestBuilder
that could be retrieved by CameraDevice
. CameraDevice is the main object that have all features of Android camera device).
Steps
In this example, I will change white balance
and adjust focus as auto focus
.
You can get the instance of CameraDevice
from cameraDeviceSessionCallback
.
The following example really helped for me.
1. retrive CameraRequestBuilder
from cameraDeive
val captureRequestBuilder = cameraDevice?.createCaptureRequest(CameraDevice.TEMPLATE_MANUAL)
2. Set repoeating request that you want to change your camera parameters
captureRequestBuilder?.run {
addTarget(surfaceView!!.holder.surface)
set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_OFF)
set(CaptureRequest.COLOR_CORRECTION_MODE, CameraMetadata.COLOR_CORRECTION_MODE_TRANSFORM_MATRIX)
set(CaptureRequest.COLOR_CORRECTION_GAINS, getRggbChannelVector(to))
set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE)
CameraManagerWrapper.cameraOps.cameraCaptureSession?.setRepeatingRequest(
this.build(),
CameraManagerWrapper.cameraOps.captureCallbackListener,
null,
)
CameraManagerWrapper.cameraOps.captureRequestBuilder = captureRequestBuilder
}
You can set the second parameter in the setRepeatingRequest
. But I reccoment to set it due to save the camera parameter's context. And you can get latest camera parameters from CaptureResult(TotalCaptureResult)::get()
CameraManagerWrapper.cameraOps.cameraCaptureSession?.setRepeatingRequest(
this.build(),
CameraManagerWrapper.cameraOps.captureCallbackListener,//⭐️ here
null,
)
コメント