Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Camera2 Output sizes

I have tested new Camera2 API on Android Lollipop. I want to fetch supported preview size:

StreamConfigurationMap streamConfigurationMap = cameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);
Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);

and the maximum preview size is 1440x1080px on Samsung Galaxy Tab S that has 2560x1600px resolution. So my previewSize is 1440x1080px and TextureView surface size is 2560x1600px so image is distorted.

I tested old Camera API that is deprecated.

Camera.Parameters parameters =  camera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();

And the code above returns 32 varius combinations of preview size such as: 2560x1920, 1920x1080, 1080x1920, 2560x2560 etc. In that case I am able to choose optimal size and display correct image.

I do not know how to force new API to get optimal size. I know that the solution is to resize down view that displays preview, but built-in camera app works in fullscreen mode correctly. Thanks in advance for all suggestions!

like image 556
piotrpawlowski Avatar asked Jul 11 '15 21:07

piotrpawlowski


2 Answers

replace

Size[] sizes = streamConfigurationMap.getOutputSizes(SurfaceTexture.class);

to

Size[] sizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG)
like image 163
Volodymyr Zakharov Avatar answered Sep 17 '22 15:09

Volodymyr Zakharov


As @Alex Cohn said it depends on the manufacturers to embrace Camera API2.

You can check if the Camera API2 is supported with camCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); returning an int corresponding to the level of support for Camera API2. If the level you get is equal to CameraMetadata.INFO_SUPPORTED_HARDWARE_LEVEL_LEGACYbasically your phone manufacturer does not support Camera API2.

--> As a consequence the SCALER_STREAM_CONFIGURATION_MAP may return different resolutions than the ones accessible with Camera API1. This is the reason why you get

the maximum preview size is 1440x1080px

What really shocks me it that the question was asked 4 years ago... and there are still manufacturers that did not care to upgrade to Camera API2. While Camera API2 gives you much more features, maybe Camera API1 is not dead after all.

Would be nice to have some fragmentation information, at least to know how many devices you actually target if you use Camera API2 (it's not all the Android L and above because of the LEGACY support, developers deserve to know that)

like image 39
dnhyde Avatar answered Sep 20 '22 15:09

dnhyde