Android matching the camera picture size to a phone's screen size
I've an app that takes a camera shot and saves the jpeg on the sdcard. When i load the jpeg it is much larger than the screen. how can i display the picture to the same size as the screen as it looked in the camera preview? i've w开发者_StackOverflowritten code to get the hardware's screensize in pixels and i've logged out the camera's available picture sizes eg
public void surfaceCreated(SurfaceHolder holder) {
Log.e(TAG, "surfaceCreated");
mCamera = Camera.open();
Parameters params = mCamera.getParameters();
List sizes = params.getSupportedPictureSizes();
int w = getResources().getDisplayMetrics().widthPixels;
int h = getResources().getDisplayMetrics().heightPixels;
Log.e(TAG, "*********** hardware screen height size = "+ h);
Log.e(TAG, "*********** hardware screen width size = "+ w);
for(int i = 0; i<sizes.size();i++){
int height;
int width;
Camera.Size cs = (Size) sizes.get(i);
height = cs.height;
width = cs.width;
Log.e(TAG, "*********** camera picsize = "+ height +" X " +width);
}
}
output:
07-18 20:59:37.567: ERROR/CameraTest(4394): *********** hardware screen height size = 480
07-18 20:59:37.567: ERROR/CameraTest(4394): *********** hardware screen width size = 320
07-18 20:59:37.572: ERROR/CameraTest(4394): *********** camera picsize = 1536 X 2048
07-18 20:59:37.572: ERROR/CameraTest(4394): *********** camera picsize = 1200 X 1600
07-18 20:59:37.577: ERROR/CameraTest(4394): *********** camera picsize = 768 X 1024
solved:
public void surfaceCreated(SurfaceHolder holder) {
Log.e(TAG, "surfaceCreated");
mCamera = Camera.open();
Parameters params = mCamera.getParameters();
int w = getResources().getDisplayMetrics().widthPixels;
int h = getResources().getDisplayMetrics().heightPixels;
try{
params.setPictureSize(h, w);
mCamera.setParameters(params);
} catch (Exception e) {
e.printStackTrace();
}
}
精彩评论