I am using a custom camera and used the full-screen resolution to display the preview in the entire screen of the device. We have a native method to get all supported size for the picture, preview and video either using Camera
or Camera Manager
for all types of device. Check below code which I used to retrieve all supported size for the camera.
Using Camera
Camera.Parameters parameters = mCameraHelper.getCamera().getParameters(); // Images supported size by device List<Camera.Size> pictureSizes = parameters.getSupportedPictureSizes(); // Camera Preview supported size by device List<Camera.Size> previewSizes = parameters.getSupportedPreviewSizes(); // Video supported size by device List<Camera.Size> videoSizes = parameters.getSupportedVideoSizes();
Using Camera Manager
CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE); try { for (String cameraId : manager.getCameraIdList()) { CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); StreamConfigurationMap map = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP); // Images supported size by device Size[] pictureSizes = map.getOutputSizes(ImageFormat.JPEG); // Video supported size by device Size[] videoSizes = map.getOutputSizes(MediaRecorder.class); } } catch (CameraAccessException e) { e.printStackTrace(); Log.e(TAG, "setUpCameraOutputs: catch: " + e.getMessage()); } catch (NullPointerException e) { Log.e(TAG, "setUpCameraOutputs: catch: " + e.getMessage()); }
I have used this code and tested in Samsung A8+ device and Below are the sizes which I get in output after running above code.
==============================================
================ Preview size ============
Preview size : 0 : Width: 1080 , Height: 1920
Preview size : 1 : Width: 1080 , Height: 1440
Preview size : 2 : Width: 1088 , Height: 1088
==============================================
================ Picture size ============
Picture size : 0 : Width: 3456 , Height: 4608
Picture size : 1 : Width: 2592 , Height: 4608
Picture size : 2 : Width: 3456 , Height: 3456
Picture size : 3 : Width: 2448 , Height: 3264
Picture size : 4 : Width: 1836 , Height: 3264
Picture size : 5 : Width: 2448 , Height: 2448
Picture size : 6 : Width: 1152 , Height: 2048
Picture size : 7 : Width: 1080 , Height: 1920
==============================================
================ Video size ==============
Video size : 0 : Width: 1080 , Height: 1920
Video size : 1 : Width: 1080 , Height: 1440
Video size : 2 : Width: 1072 , Height: 1072
Comparing to above output size to real native Samsung A8+ device camera sizes which are listed below. From that, I want an 18.5:9 ratio size which is TAG as "I need this size" in below list.
==============================================
================ Picture size ============
Picture size : 0 : Width: 3456 , Height: 4608
Picture size : 1 : Width: 2592 , Height: 4608
Picture size : 2 : Width: 2240 , Height: 4608 <--- I need this size
Picture size : 3 : Width: 3456 , Height: 3456
Picture size : 4 : Width: 1836 , Height: 3264
Picture size : 5 : Width: 2448 , Height: 2448
==============================================
================ Video size ==============
Video size : 0 : Width: 1080 , Height: 1920
Video size : 1 : Width: 1080 , Height: 2224 <--- I need this size
Video size : 2 : Width: 1072 , Height: 1072
Video size : 2 : Width: 720 , Height: 1280
Video size : 2 : Width: 480 , Height: 640
My Query: When I used a higher resolution for full-screen preview from output size using above code, Camera preview stretch because it doesn't have resolutions of 18.5:9 ratio.
So, How can I get this type of resolution like 18:9 or 18.5:9 ratio, which is available in nowadays in new devices we called full-vision device or notch display. I need proper solutions which can works in all devices and give me the same size which is listed in the device native camera for full-screen for camera preview.