Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Determine Android Device's Camera Height and Width

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!

like image 989
Monica Negapatan Avatar asked Aug 16 '26 04:08

Monica Negapatan


1 Answers

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); 
like image 123
Rui Marques Avatar answered Aug 18 '26 18:08

Rui Marques



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!