I am testing my Android app on a Samsung Galaxy Tab. When I open up the camera application on the tablet, I see that the possible resolutions you can set for the camera are:
However, when I open up a camera instance in my Android app and fetch the supported preview sizes, I get the following resolutions:
Why is there such a discrepancy in the supported resolutions? I want my custom camera activity to have a full screen camera, and I can't do it with resolutions that are smaller than the screen size (which my app says is 800 x 1344).
// fetch screen size
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels+navBarHeight;
Log.d(TAG, "screen width and height: " + width + " " + height);
// get supported preview sizes
Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
cameraCount = Camera.getNumberOfCameras();
for(int camIdx = 0; camIdx < cameraCount; camIdx++){
Camera.getCameraInfo( camIdx, cameraInfo );
if(cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK){
try {
c = Camera.open(); // attempt to get a Camera instance
for(int i =0; i< c.getParameters().getSupportedPreviewSizes().size(); i++){
Size size = c.getParameters().getSupportedPreviewSizes().get(i);
Log.d(TAG, "supported preview size: " + size.width + " " + size.height);
}
} catch (Exception e) {
// Camera is not available (in use or does not exist)
e.printStackTrace();
}
} else if(cameraCount == 1 && cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
// device only has a front facing camera
try {
c = Camera.open(camIdx); // attempt to get a Camera instance
} catch (Exception e) {
// Camera is not available (in use or does not exist)
e.printStackTrace();
}
}
}
Why is there such a discrepancy in the supported resolutions?
Picture resolutions and preview resolutions are not the same thing. The former is for pictures. The latter is for the preview frames.
I want my custom camera activity to have a full screen camera, and I can't do it with resolutions that are smaller than the screen size (which my app says is 800 x 1344).
Yes, you can. Android will happily stretch or shrink your preview frames to match the size of the TextureView
or SurfaceView
that you are using for the preview. In fact, such stretching or shrinking is pretty much unavoidable, since it is rather unlikely that the camera will support some arbitrary preview resolution, one that happens to match whatever you are choosing for your preview View
size.