Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
214 views
in Technique[技术] by (71.8m points)

android - Set Camera Size - Parameters vs Intent?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...