Set Camera Size - Parameters vs Intent?

android, android-camera

Solution

This code allows me to pick image from gallery. Crop and use my aspect ratio. I did similar code for using camera. After user takes picture, it immediately launches an activity to crop the picture.

  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);

Problem

I am currently using an intent to take a picture, like this: ``` 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); ``` But I really need to set the image size as close to a square as possible. So after researching it seems you need to do something like this: ``` 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); ``` My questions are, do these work together or is it an either/or? Which method works best for my needs? Again, I have 96px by 96px box for user profile pics. After user takes the picture I want the image to fill entire box without stretching. Is the best way to set size at the point of picture being taken, or alter the `imageView` or `bitmap` (or ...?) after the fact? OR, should I just let the users crop the picture and I can define the cropping area dimensions? Edit: See bounty for updated question.

Original source