Open vtangade opened 1 year ago
I also need this information
Can someone answer?
If you are using something like BarcodeView, extend it and implement CameraPreview.StateListener, CameraParametersCallback. Then in the constructors, after calling the super, call addStateListener(this)
In the override for previewStarted(), call changeCameraParameters(this). That will pass the callback down to the CameraManager which will then get called to set the desired parameters
public Camera.Parameters changeCameraParameters(Camera.Parameters params) { params.setZoom(params.getMaxZoom() / 2) return params; }
setZoom() uses an index into the available zooms list which you can get from Camera.Parameters if you want to see what values you are dealing with. A Galaxy S22 goes up to 8x, so getMaxZoom() / 2 is about 4x
(Note: BarcodeView doesn't need to implement CameraPreview.StateListener since it has it's own previewStarted function that you can override, but other components you are extending may not have that helper)
Kotlin example:
val camera = barcodeView.barcodeView.cameraInstance ?: return
camera.changeCameraParameters { params: Camera.Parameters ->
if (params.isZoomSupported) {
val maxZoom = params.maxZoom
val newZoomLevel = Math.min(maxZoom, zoomLevel.toInt())
params.zoom = newZoomLevel
}
params
}
where zoomLevel is a Float parameter.
I want to set Zoom in Camera but not able achieve this using Zxing, please suggest any solution.
I'm currently using following version :