A View for cropping images that is similar to Instagram's crop which allows a range of aspect ratios instead of a solid ratio. Also an Activity for cropping is
A View for cropping images that is similar to Instagram's crop which allows a range of aspect ratios instead of a solid ratio. Also an Activity for cropping is
A View for cropping images that is similar to Instagram's crop. Also an Activity for cropping is included.
Add the dependency:
dependencies {
implementation 'com.yashoid:instacropper:1.2.0'
}Add InstaCropperView to your xml layout
InstaCropperView receives only Uri but any Uri is possible.
mInstaCropper.setImageUri(imageUri);You can specify three size ratios for the crop. The narrowest allowed, the widest allowed and the ideal ratio. The View will adjust its size by the ideal ratio.
mInstaCropper.setRatios(defaultRatio, minimumRatio, maximumRatio);The cropped image is returned in a callback. You can specify MeasureSpec to adjust the width and height of the returned Bitmap.
mInstaCropper.crop(
View.MeasureSpec.makeMeasureSpec(1024, View.MeasureSpec.AT_MOST),
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
new InstaCropperView.BitmapCallback() {
@Override
public void onBitmapReady(Bitmap bitmap) {
// Do something.
}
}
);It is also possible to use the crop feature via an Intent call. There are various getIntent() methods defined on InstaCropperActivity. You will then receive the crop result in data.getData().
Intent intent = InstaCropperActivity.getIntent(context, srcUri, dstUri, maxWidth, outputQuality);
startActivityForResult(intent, REQUEST_CROP);Cropping of multiple images is also possible. Use MultipleCropActivity.getIntent() methods to access. If all the images are cropped you will receive RESULT_OK otherwise RESULT_CANCELED. EXTRA_COUNT will contain the number of images cropped.
Intent intent = MultipleCropActivity.getIntent(context, srcUris, dstUris, maxWidth, maxHeight, aspectRatio);
startActivityForResult(intent, REQUEST_MULTIPLE_CROP);You can modify the crop Activity's apprearance by overriding the following resouce values:
Crop
Crop
@android:color/white
@android:color/black
No open issues yet, or sync has not completed.