Reputation: 538
I am making a custom camera app, and I am using the Android Camera API for that. I know this API is deprecated now and it is recommended to use the Camera2 API. But I have to only preview the camera with some zoom.
Below is the code for setting the zoom
Camera.Parameters parameters = camera.getParameters();
parameters.setZoom(30);
parameters.setPreviewFpsRange(
previewFpsRange[Camera.Parameters.PREVIEW_FPS_MIN_INDEX],
previewFpsRange[Camera.Parameters.PREVIEW_FPS_MAX_INDEX]);
parameters.setPreviewFormat(IMAGE_FORMAT);
camera.setParameters(parameters);
Now, the problem is that the camera zoom is not equal across devices, some devices zoom in to a good amount whereas some devices zoom very much.
I am not able to find any explanation over the internet regarding the same.
I need the same zoom level across all the Android devices irrespective of the camera quality and MP.
Upvotes: 2
Views: 860
Reputation: 1327
The legal Value of Camera.Parameters.setZoom() goes from 0 to Camera.Parameters.getMaxZoom() as you can read in the Documentation of setZoom()
What you have to do is to normalize the Zoom factor over all devices, which can be done with the following method:
private setZoom(float zoom) {//to me, here zoom 0 to 1
try {
if (isCameraOpened() && mCameraParameters.isZoomSupported()) {
int maxZoom = mCameraParameters.getMaxZoom();
int scaledValue = (int) (zoom * maxZoom);
mCameraParameters.setZoom(scaledValue);
mZoom = zoom;
mCamera.setParameters(mCameraParameters);
}
} catch (Exception | Error throwable) {
Log.e(TAG, Objects.requireNonNull(throwable.getMessage()));
}
}
Upvotes: 1