How to adjust brightness of camera using CameraX?

1,460 views
Skip to first unread message
Assigned to wenhu...@google.com by wuj...@google.com

Mohit Shetty

unread,
Sep 24, 2021, 12:28:47 PM9/24/21
to Android CameraX Discussion Group
I'm trying to create a seekbar to adjust brightness of the camera. I tried going through the documentation, but couldn't really find anything related to it. After researching on the internet for a while, I got to know that CameraX doesn't directly support any way to adjust the brightness of the camera, but it can be done via the Camera2 API.

What I actually wanted to know is why doesn't CameraX support adjusting brightness by value yet? Are there any risks/problems here while supporting all/multiple devices and if it is, then what's the safest way to adjust brightness while supporting all/maximum devices?

Wenhung Teng

unread,
Sep 27, 2021, 12:41:32 AM9/27/21
to Android CameraX Discussion Group, shetty...@gmail.com
Hi, seems like the exposure compensation API can help you, 
The exposure API is located at CameraControl:
///////////////
interface CameraControl {

    fun setExposureCompensationIndex(value: Int): ListenableFuture<Int?>

}

///////////////

This API can make adjustments to the exposure based on the auto-exposure. API doc please see here.
There is a sample app that uses the above API to adjust the brightness via the seekbar, you can have a try on this. 
And please feel free to inform us if you have other scenes that need to be more precisely (manual) exposure control on the camera, I think the Camera2Interop could be another way that can help you to set the control options to the camera.


shetty...@gmail.com 在 2021年9月25日 星期六上午12:28:47 [UTC+8] 的信中寫道:

Mohit Shetty

unread,
Oct 2, 2021, 6:20:50 AM10/2/21
to Android CameraX Discussion Group, wenhu...@google.com, Mohit Shetty
Hey Wenhug,

Thanks a lot for sharing the sample app. I have already implemented an seekbar option for the exposure and now want to include a seekbar option for brightness as well as seen in any other major camera app (for e.g. the Google Camera app). Although the effects of altering exposure and brightness might seem interchangeably similar, they are not actually. Exposure deals with the amount of light the camera is exposed to and brightness deals with how bright (or dark) a picture is. 

We're trying to stick to using CameraX library so using Camera2Interop might not really be an option. Hope that this option gets soon added to CameraX officially!

Thanks a lot for your time and efforts to bring such a good and useful library that was actually needed considering all the device specific issues the Camera2 API has. The library really helps in building easy to maintain apps.

Regards,
Mohit

Eddie Kezeli

unread,
Jul 12, 2022, 2:51:22 PM7/12/22
to Android CameraX Discussion Group, wenhu...@google.com
Hello,

I've noticed in my CameraX app that lowering the exposure compensation using setExposureCompensationIndex() decreases the brightness only in the viewfinder, while the captured image remains well exposed. Your sample app exhibits the same behavior.

The only workaround I've found so far is to set Noise Reduction to NOISE_REDUCTION_MODE_OFF. Somehow this allows for captured images to be under or over exposed as desired. Am I missing a step, or is this a known bug? These tests were performed on a Pixel 4a with Android 12, using CameraX 1.0.1 and 1.2.0 alpha 2.

Thank you for your help!

Wenhung Teng

unread,
Jul 13, 2022, 10:01:49 AM7/13/22
to Android CameraX Discussion Group, edee...@gmail.com, Wenhung Teng
Hi, this is a known issue that happens to specific Pixel models. 
The reason for this issue is because the device enables the HDR+ in the still capturing, and it unexpectedly overrides the exposure compensation effect.
NOISE_REDUCTION_MODE_HIGH_QUALITY is one of the keys that is required for the HDR+ function. By setting the NOISE_REDUCTION_MODE_OFF will disable the HDR+ and correct the exposure.
Some other options like EDGE_MODE_FAST, COLOR_CORRECTION_ABERRATION_MODE_FAST may also disable the HDR+ function.

We have already informed the Pixel device team about this issue. I'd recommend setting one of the options above to disable the HDR+ as a temporary solution.
But please be aware, the workaround may only work with specific Pixel device models, please only apply the change for these Pixel devices.

edee...@gmail.com 在 2022年7月13日 星期三凌晨2:51:22 [UTC+8] 的信中寫道:

Eddie Kezeli

unread,
Jul 13, 2022, 11:19:39 AM7/13/22
to Android CameraX Discussion Group, wenhu...@google.com, Eddie Kezeli
Thank you for the reply! Great explanation, glad to know I'm not going crazy 😆 Do you happen to know which Pixel devices are affected?

Wenhung Teng

unread,
Jul 14, 2022, 5:45:51 AM7/14/22
to Android CameraX Discussion Group, edee...@gmail.com, Wenhung Teng
The exact device list might need to clarify with the device team, that may need time to investigate.
It seems like Pixel 6 doesn't have this issue. Probably you can try to disable HDR+ on Pixel 4a, 4a (5G),  5, 5a (5G), these devices possibly have this issue and we can disable the HDR+ with the options we mentioned before.


edee...@gmail.com 在 2022年7月13日 星期三晚上11:19:39 [UTC+8] 的信中寫道:
Reply all
Reply to author
Forward
0 new messages