android-crop icon indicating copy to clipboard operation
android-crop copied to clipboard

is is possible to set fixed crop ratio

Open Amirhgh74 opened this issue 8 years ago • 1 comments

i want to have crop ratio to be fixed but not something like square , is it possible that i set the ratio to be cropped ?

Amirhgh74 avatar May 27 '17 08:05 Amirhgh74

@Amirhgh74 Yes it is possible. You can do it using the following line.

Crop.of(source, destination).withAspect(ASPECT_X, ASPECT_Y).start(context, Class/Fragment here);

You would do this in the onActivityResult. This is how I do it to get a 16:9 ratio image:

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
	if (requestCode == Crop.REQUEST_PICK && resultCode == Activity.RESULT_OK) {
		beginCrop(data.getData());
	} else if (requestCode == Crop.REQUEST_CROP) {
		handleCrop(resultCode, data);
	}
}

private void beginCrop(Uri source) {
	Uri destination = Uri.fromFile(new File(getActivity().getCacheDir(), "cropped"));
	Crop.of(source, destination).withAspect(ASPECT_X, ASPECT_Y).start(getActivity(), RegistrationDialog.this);
}

If you look at the source code for the class Crop, you'll see the default aspect ratio is 1:1 but that there are a couple methods where you can set your own aspect ration.

power7714 avatar Aug 03 '17 20:08 power7714