Android相机参数图像大小

时间:2013-04-04 04:40:25

标签: android

嗨以下是我启动相机的方法。我总是得到320 x 240的图像大小。有关如何进行设置以使相机拍摄出具有设备支持的最大尺寸的图像的想法吗?

      File photo = null;
         String FILE_NAME ="20143";
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
if (android.os.Environment.getExternalStorageState().equals(
        android.os.Environment.MEDIA_MOUNTED)) {
    photo = new File(android.os.Environment.getExternalStorageDirectory(), FILE_NAME);
} else {
    photo = new File(getCacheDir(), FILE_NAME);
}    
if (photo != null) {
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    selectedImageUri = Uri.fromFile(photo);
    startActivityForResult(intent, CAMERA_PIC_REQUEST);
}

1 个答案:

答案 0 :(得分:1)

获取设备支持的所有尺寸

Camera.Parameters parameters = mCamera.getParameters();
List<Camera.Size> sizes = parameters.getSupportedPictureSizes();

我正在使用以下方法获得最佳尺寸

private Camera.Size getBestPreviewSize(int width, int height,
        Camera.Parameters parameters) {
    Camera.Size result = null;

    for (Camera.Size size : parameters.getSupportedPictureSizes()) {
        Log.d("size: ", size.width + ":" + size.height);
        if (size.width <= width && size.height <= height) {
            if (result == null) {
                result = size;
            } else {
                int resultArea = result.width * result.height;
                int newArea = size.width * size.height;

                if (newArea > resultArea) {
                    result = size;
                }
            }
        }
    }

    return (result);
}
带有int width, int height

是surfaceHolder的宽度,高度。