Determine Android Device's Camera Height and W

2019-02-25 22:04发布

问题:

I was trying to think over of a solution that an application's screen size will be flexible on different screen sizes of devices. I thought of getting the device's camera height and width. Is there a function that we can call in Java that gets the device's camera's height and width and the returned values will be assigned to the variables CAMERA_WIDTH and CAMERA_HEIGHT? or any ways to do it? aside from assigning it with real numbers. THANK YOU!

回答1:

This is a way:

Camera.Parameters params = mCamera.getParameters(); // mCamera is a Camera object
List<Camera.Size> sizes = params.getSupportedPreviewSizes();

// position: variable where you choose between different supported resolutions, 
// this varies from phone to phone, even the order can be different, 
// ex. ascending or descending order.

mFrameWidth = (int) sizes.get(position).width;
mFrameHeight = (int) sizes.get(position).height;

params.setPreviewSize(mFrameWidth, mFrameHeight);
mCamera.setParameters(params);