How can I create an automatic zoom and default zoom with cameraX/CameraController on Java?

183 views
Skip to first unread message

Andre Tauk

unread,
May 14, 2021, 5:18:14 PM5/14/21
to Android CameraX Discussion Group

(I posted this question on stackOverflow, but got no answer)

This is the code I'm using, a can only change the zoom level by sliding the seekbar, not automatically. Neither select a default zoom level.

I'm using this example of cameraX/CameraController: 

https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:camera/integration-tests/viewtestapp/src/main/java/androidx/camera/integration/view/CameraControllerFragment.java?q=CameraControllerFragment&ss=androidx

SeekBar linearZoomSlider = findViewById(R.id.linear_zoom_slider); linearZoomSlider.setOnSeekBarChangeListener(

new SeekBar.OnSeekBarChangeListener() {

  @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean b) { checkFailedFuture(mCameraController.setLinearZoom(
 (float) progress / seekBar.getMax()
)); }

  @Override public void onStartTrackingTouch(SeekBar seekBar) { 
 } 

  @Override public void onStopTrackingTouch(SeekBar seekBar) { 
} });

Patrick Liao

unread,
May 15, 2021, 11:42:57 AM5/15/21
to Android CameraX Discussion Group, and...@gmail.com
Hi,

Would you provide more information about "automatic"? (i.e. what do you mean by "automatic"?) 
And for changing zoom ratio, you can do (ProcessCameraProvider object).getCameraControl().setZoomRatio(float ratio) directly if this is what you are looking for.

Cheers,
Patrick Liao

Patrick Liao

unread,
May 15, 2021, 11:47:14 AM5/15/21
to Android CameraX Discussion Group, Patrick Liao, and...@gmail.com
Sorry for the typo :(

I mean  (androidx.camera.core.Camera object).getCameraControl().setZoomRatio(float ratio), and the Camera object could be obtained ProcessCameraProvider.bindToLifeCycle(args) (The same one for binding CameraX use cases and this function would return Camera object). 

Reply all
Reply to author
Forward
0 new messages