设置相机大小 - 参数与意图?

The*_*ter 13 android android-camera

我目前正在使用意图拍照,如下所示:

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
intent.putExtra("return-data", true);
startActivityForResult(intent, CAMERA_REQUEST);
Run Code Online (Sandbox Code Playgroud)

但我真的需要将图像大小设置为尽可能接近正方形.所以在研究之后,你似乎需要做这样的事情:

Camera camera = Camera.open();
Parameters params = camera.getParameters();
List<Camera.Size> sizes = params.getSupportedPictureSizes();

// Once you will see the supported Sizes, you can define them with the method :

setPictureSize(int width, int height);
Run Code Online (Sandbox Code Playgroud)

我的问题是,这些是一起工作还是一个或两个?哪种方法最适合我的需求?

同样,我有96px到96px的盒子用于用户个人资料图片.用户拍摄照片后,我希望图像无需拉伸即可填满整个盒子.是在拍摄照片时设置尺寸的最佳方法,还是在事后改变imageViewbitmap(或......?)?或者,我应该让用户裁剪图片,我可以定义裁剪区域尺寸吗?

编辑:请参阅赏金以获取更新的问题.

The*_*ter 17

此代码允许我从图库中选择图像.裁剪并使用我的宽高比.我使用相机做了类似的代码.用户拍照后,立即启动活动裁剪图片.

  Intent photoPickerIntent = new Intent(
                        Intent.ACTION_PICK,
                        android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                photoPickerIntent.setType("image/*");
                photoPickerIntent.putExtra("crop", "true");
                photoPickerIntent.putExtra("outputX", 150);
                photoPickerIntent.putExtra("outputY", 150);
                photoPickerIntent.putExtra("aspectX", 1);
                photoPickerIntent.putExtra("aspectY", 1);
                photoPickerIntent.putExtra("scale", true);
                photoPickerIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
                photoPickerIntent.putExtra("outputFormat",
                        Bitmap.CompressFormat.JPEG.toString());
                startActivityForResult(photoPickerIntent, RESULT_LOAD_IMAGE);
Run Code Online (Sandbox Code Playgroud)

  • 这是否也适用于捕获意图? (4认同)
  • 使用Intent photoPickerIntent = new Intent("android.media.action.IMAGE_CAPTURE"); 用于相机,并删除photoPickerIntent.setType("image/*"); (2认同)
  • 如果你想从相机而不是画廊 (2认同)

Moe*_*sio 6

您可以使用Bitmap.createScaleBitmap(Bitmap src, int destWidth, int destHeight, boolean filter)来调整位图的大小