InstaCropper

A View for cropping images that is similar to Instagram's crop which allows a range of spect ratios. Also an Activity for cropping is included.

License

License

GroupId

GroupId

com.yashoid
ArtifactId

ArtifactId

instacropper
Last Version

Last Version

1.0.6
Release Date

Release Date

Type

Type

aar
Description

Description

InstaCropper
A View for cropping images that is similar to Instagram's crop which allows a range of spect ratios. Also an Activity for cropping is included.
Project URL

Project URL

https://github.com/yasharpm/InstaCropper
Source Code Management

Source Code Management

https://github.com/yasharpm/InstaCropper

Download instacropper

How to add to project

<!-- https://jarcasting.com/artifacts/com.yashoid/instacropper/ -->
<dependency>
    <groupId>com.yashoid</groupId>
    <artifactId>instacropper</artifactId>
    <version>1.0.6</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.yashoid/instacropper/
implementation 'com.yashoid:instacropper:1.0.6'
// https://jarcasting.com/artifacts/com.yashoid/instacropper/
implementation ("com.yashoid:instacropper:1.0.6")
'com.yashoid:instacropper:aar:1.0.6'
<dependency org="com.yashoid" name="instacropper" rev="1.0.6">
  <artifact name="instacropper" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.yashoid', module='instacropper', version='1.0.6')
)
libraryDependencies += "com.yashoid" % "instacropper" % "1.0.6"
[com.yashoid/instacropper "1.0.6"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

NOTICE: I build custom views "for free". Just send me a description of what you need and I will send it to you the next day! Email me at yasharpm[at]gmail[dot]com with the subject "CustomView request".

InstaCropper

A View for cropping images that is similar to Instagram's crop. Also an Activity for cropping is included.

alt tag

Usage

Add the dependency:

dependencies {
	implementation 'com.yashoid:instacropper:1.2.0'
}

How to use this library

Add InstaCropperView to your xml layout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.yashoid.instacropper.InstaCropperView
        android:id="@+id/instacropper"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:backgroundColor="@android:color/white" />

</FrameLayout>

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:

<string name="instacropper_title">Crop</string> <!-- Title of toolbar -->
<string name="instacropper_crop">Crop</string> <!-- Title of crop action in toolbar -->

<color name="instacropper_cropper_background">@android:color/white</color> <!-- Background color of InstaCropperView in the activity -->
<color name="instacropper_crop_color">@android:color/black</color> <!-- Color of crop action in toolbar -->

<style name="InstaCropper" parent="android:style/Theme.DeviceDefault.Light"/> <!-- Style of crop Activity -->

Versions

Version
1.0.6
1.0.5
1.0.4
1.0.2