3

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!

Monica Negapatan
  • 251
  • 1
  • 14
  • 29

1 Answers1

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