Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ho to set Zoom in Camera using Zxing #728

Open
vtangade opened this issue Nov 4, 2022 · 4 comments
Open

Ho to set Zoom in Camera using Zxing #728

vtangade opened this issue Nov 4, 2022 · 4 comments

Comments

@vtangade
Copy link

vtangade commented Nov 4, 2022

I want to set Zoom in Camera but not able achieve this using Zxing, please suggest any solution.

I'm currently using following version :

implementation 'com.journeyapps:zxing-android-embedded:4.3.0'
@massimilianochiodi
Copy link

I also need this information

@yersx
Copy link

yersx commented Mar 20, 2023

Can someone answer?

@douglas-fp
Copy link

douglas-fp commented Jun 13, 2023

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)

@sarkiroka
Copy link

sarkiroka commented Aug 26, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants