Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

android - Configure CameraX (flash mode, auto white balance mode, action mode etc)

I've already successfully implemented CameraX, however, I am stuck on configuring its settings. I'd like to set auto white balance, noise reduction, flash and focus mode (just like in Camera2). So far, the only things I found on SO refer only to Camera2 and the official documentation doesn't tell me much either. Is it even possible to set these modes on CameraX or is only Camera2 supported so far?

question from:https://stackoverflow.com/questions/65898149/configure-camerax-flash-mode-auto-white-balance-mode-action-mode-etc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You're correct, the documentation is quite poor (I suppose because the library has been in alpha up until recently).

To change the flash mode:

Keep a reference to the ImageCapture object when binding:

    imageCapture = ImageCapture.Builder()
        .setFlashMode(ImageCapture.FLASH_MODE_AUTO)
        .setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY)
        .setTargetAspectRatio(aspectRatio)
        .setTargetRotation(rotation)
        .build()

When you want to change the flash mode (e.g when the user taps the flash icon):

flashMode = ImageCapture.FLASH_MODE_OFF

Focus and metering are a little bit more involved, you can see the classes you should be using here.

As for noise reduction and white balance, I believe you'll need to still need to use the Camera2 libraries.

implementation "androidx.camera:camera-camera2:${camerax_version}"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...