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!
Asked
Active
Viewed 6,435 times
1 Answers
4
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);

Rui Marques
- 8,567
- 3
- 60
- 91
-
What is position? – e-info128 Jan 01 '17 at 20:27
-
Position is the sizes list index. Check the content from the sizes list and choose one of its sizes. – Rui Marques Jan 01 '17 at 23:17