Reputation: 23
I am clicking a photo using CameraX library and want to change exposure settings. What do I do to set the Exposure Compensation or change the exposure settings of picture captured?
// Set up the capture use case to allow users to take photos
val imageCaptureConfig = ImageCaptureConfig.Builder().apply {
setLensFacing(lensFacing)
setCaptureMode(CaptureMode.MIN_LATENCY)
// We request aspect ratio but no resolution to match preview config but letting
// CameraX optimize for whatever specific resolution best fits requested capture mode
setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}.build()
imageCapture = ImageCapture(imageCaptureConfig)
// Setup image analysis pipeline that computes average pixel luminance in real time
val analyzerConfig = ImageAnalysisConfig.Builder().apply {
setLensFacing(lensFacing)
// Use a worker thread for image analysis to prevent preview glitches
setCallbackHandler(Handler(analyzerThread.looper))
// In our analysis, we care more about the latest image than analyzing *every* image
setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}.build()
Upvotes: 2
Views: 2190
Reputation: 20614
CameraX 1.0.0-beta09 has added an experimental interface for ExposureCompensation
You can set exposure by:
val camera = cameraProvider.bindToLifecycle(viewLifecycleOwner, cameraSelector, preview, imageCapture)
val cameraControl = camera.cameraControl
cameraControl.setExposureCompensationIndex(exposure)
Upvotes: 2
Reputation: 626
val imageCaptureBuilder = ImageCapture.Builder().apply {
setLensFacing(lensFacing)
setCaptureMode(CaptureMode.MIN_LATENCY)
// We request aspect ratio but no resolution to match preview config but letting
// CameraX optimize for whatever specific resolution best fits requested capture mode
setTargetAspectRatio(screenAspectRatio)
// Set initial target rotation, we will have to call this again if rotation changes
// during the lifecycle of this use case
setTargetRotation(viewFinder.display.rotation)
}
Camera2Interop.Extender(imageCaptureBuilder).setCaptureRequestOption(
CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, exposure)
imageCapture = imageCaptureBuilder.build()
where exposure
is your desired value
Ideally you should query the CONTROL_AE_COMPENSATION_RANGE
to set a valid value for exposure
.
Upvotes: 3