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);