Fork me on GitHub

NoCropper - Android Library for Cropping

Posted on 13 November 2015
Under Project
Tagged
Android
NoCropper - Android Library for Cropping | Jay Rambhia’s Blog

Finally, after more than a year of working with Android, I’m releasing my first Open Source Library for Android. As the title says, the library is named NoCropper. It’s a lightweight library for cropping images. Since it doesn’t use any special features of Android, it is compatible with 11+ version of android (it uses ValueAnimator).

What’s So Special About It

Well, It’s my first open source library. Apart from that, it’s a simple image cropper which also lets user not crop the image and convert it to square with fancy animations.

Demo

Here’s a poorly made gif and YouTube video for you.

cropper_demo

GitHub Repo

Here’s the GitHub Repo

How To Use In Your Android Project

Just add the following dependency in your build.gradle file.

dependencies {
    compile 'com.fenchtose.nocropper:nocropper:0.1.3'
}

Following repositories can be added

Maven

repositories {
    maven {
        url  "http://dl.bintray.com/jayrambhia/maven"
    }
}

JCenter

repositories {
    jcenter()
}

Code

Java

    
    CropperImageView cropperView = (CropperView)findViewById(R.id.cropper_view);
    
    // Set Bitmap
    cropperView.setImageBitmap(bitmap);
    
    // Set Max and Min Cropping
    cropperView.setMaxZoom(1.5f);
    cropperView.setMinZoom(0.8f);
    
    // set centerCrop
    cropperView.cropToCenter();
    
    // Fit image to center
    cropperView.fitToCenter();
    
    // Get Cropped Bitmap
    Bitmap croppedBitmap = cropperView.getCroppedBitmap();
    

XML Layout

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        xmlns:app="http://schemas.android.com/apk/res-auto">
        
        <com.fenchtose.nocropper.CropperView
            android:background="#ff282828"
            android:id="@+id/cropper_view"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            app:grid_opacity="0.8"
            app:grid_thickness="0.8dp"
            app:grid_color="@color/colorAccent"
            app:padding_color="#ff282828"/>
            
    </RelativeLayout>        

Here’s a sample

Check GitHub for the latest version of the library

P.S. This is quite exciting for me. Here’s a blogpost about it.

comments powered by Disqus


If you have some feedback or questions regarding this post, please add comments. I'd be happy to get some feedback.



If you liked this post, then you should follow Jay on twitter too. He would be excited to know that you like his work.