Explicitly changing CameraX focus while the camera/preview is running? (Not just when building the camera.)

Viewed 397

If you want to set the focus to a certain value (say, 10f) while building a CameraX camera, it's pretty easy ...

normally ...

    previewBuilder = new Preview.Builder();
    preview = previewBuilder.build();

launch camera with a fixed focus ...

    previewBuilder = new Preview.Builder();
    Camera2Interop.Extender x = new Camera2Interop.Extender(previewBuilder);
    x.setCaptureRequestOption(CaptureRequest.CONTROL_AF_MODE, CameraMetadata.CONTROL_AF_MODE_OFF);
    x.setCaptureRequestOption(CaptureRequest.LENS_FOCUS_DISTANCE, 10f);
    preview = previewBuilder.build();

The camera and preview will now run, with the focus fixed at "10f".

But in CameraX how do you actually change the focus to some new value, say 5f

So for example using a slider to control the focus - while the camera is actually running.

I am aware you can tap to focus, but I wanna be able to give it a value, such as "5f".

BTW I tried changing the value, on the extended builder, while the camera is running (by hanging on to the builder), which wouldn't make any sense, but in fact you can't do it anyway, you just get an error.

I investigated FocusMeteringAction and it only allows for tap-to-focus; it does not have a "set the value" function.

Any ideas?

0 Answers
Related