我有一个应用程序拍摄相机并将jpeg保存在SD卡上。当我加载jpeg时,它比屏幕大得多。如何将图片显示为与在相机预览中看到的屏幕相同的尺寸?我已经编写了代码来获取硬件的屏幕尺寸,并且我已经注销了相机的可用图片尺寸,例如
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);
}
}
输出:
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
答案 0 :(得分:0)
<强>解决:强>
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();
}
}