I've been struggling for days to create an activity that picks a image from the camera and crops it into a square shape efficiently (not loading the image into memory).
Taking the picture is no big deal:
Intent mediaPickingIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mediaPickingIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
startActivityForResult(mediaPickingIntent, REQUEST_CODE_GENERIC);
Then, I'm trying to use the OOTB cropping feature for each device like:
String cropDestinationPath = getTemporaryImagePath();
Uri destination = Uri.fromFile(new File(cropDestinationPath));
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(source, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", SQUARE_IMAGE_SIZE);
cropIntent.putExtra("outputY", SQUARE_IMAGE_SIZE);
cropIntent.putExtra("return-data", false);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, destination);
startActivityForResult(cropIntent, REQUEST_CODE_IMAGE_CROP);
Now, using the output path of the IMAGE_CAPTURE, I'm able to retrieve the exif data that says the image is rotated (i.e: 270 degrees) but the intent seems to be not caring the exif data.
I'm transforming the resulting path to an uri like:
private Uri convertPathToContentUri(String imagePath) throws Exception {
String imageName = null;
String imageDescription = null;
String uriString = MediaStore.Images.Media.insertImage(getContentResolver(), imagePath, imageName, imageDescription);
return Uri.parse(uriString);
}
BTW: I'm testing this on a Samsung device, same code on Nexus works fine.