having image distorted when mixing a view from OpenGL and the Android camera to get an image of both when using the takepicture method. I checked and found that the camera
I think the best way to get preview size, picture size
is the Camera was set up to support all Android devices. It means the preview size, picture size
you decide to set up is appropriate with the popular format that All Devices supported, ex. is 1280x720 etc.
As in following codes, is the ex. what I used.
// start preview with new settings
try {
// set preview size and make any resize, rotate or
// reformatting changes here
Camera.Parameters parameters = mCamera.getParameters();
for (Camera.Size size : parameters.getSupportedPictureSizes()) {
// 640 480
// 960 720
// 1024 768
// 1280 720
// 1600 1200
// 2560 1920
// 3264 2448
// 2048 1536
// 3264 1836
// 2048 1152
// 3264 2176
if (1600 <= size.width & size.width <= 1920) {
parameters.setPreviewSize(size.width, size.height);
parameters.setPictureSize(size.width, size.height);
break;
}
}
// Set parameters for camera
CustomCamera.mCamera.setParameters(parameters);
Camera.Size size = CustomCamera.mCamera.getParameters().getPictureSize();
mCamera.setPreviewDisplay(mHolder);
mCamera.startPreview();
} catch (Exception e) {
e.printStackTrace();
}
Best size
depend on Camera MP. So I think should use default if using Camera.
Most often, but not always, there is correspondence between picture aspect ratios and preview aspect ratios. You can be assured that at least some of them are classic 4:3 ratios (e.g. 640x480). Support for 16:9 is also widely available.
The screen may have different aspect ratio. To fill it with a camera image correctly, it is widely accepted to add black margins (same approach is used in YouTube). Alternatively, you may crop the camera image to fill the whole screen.
Note that the screen size (as reported in tech specs for the variety of devices) is not always actually available for your image display. For example, the system menus, and title bar, etc. may take their share of the screen real estate. The immersive mode is available on some devices, and its behavior depends on the system version. You may expect that future developments of Android, e.g. second screen support, will make the game even more interesting.
So, the answers to your specific questions:
is it best to use a match_parent or fitXY for the FrameLayout size and only work with two variables, the preview size and picture size? - no.
is it always the case that there will be matches in both sizes? - yes, but maybe this size is not optimal.
Even if your camera supports different "wide" picture sizes, 1280x720 preview and 2560x1440 picture may be the best match, both precisely at 16:9
. Usually, the quality of picture at small size is not significantly better than preview at that same size, so you may choose to save the preview frame if 1280x720
is what you really need.
If you can forgo takePicture()
, your app will be much more responsive.
Possible algorithm:
1) get output area aspect ratio (=width/height)
2) iterate through supported sizes:
Choose biggest one with close aspect ratio(+-5%, for example) If nothing close or resolution too low - just make yor surface(that you draw frames to) be same aspect ratio as biggest supported size and center it in parent view
Howewer, there are preview sizes & picture sizes. If you wish them to have same aspect ratio - then better choice is to use selected picture size aspect ratio in 1) This way you'll probably have to center your surface in parent view
Hope that helps)