Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 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 Reply

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}"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...