Best Android Image Cropping Libraries

Best Android Image Cropping Libraries

When you are capturing images from the Camera, you sometimes need to crop those images before saving them in external storage or uploading them to the server. Luckily there are already great and modern solutions to allow us integrate cropping capability in our android apps, be it via Kotlin or Java.

In this piece we will look at these options, how to install them and code snippets of how to use them.

(a). Croppy

This is a modern Image Cropping Library for Android with several cool features. Here are it’s features:

Double tap focus

point_up_2point_up_2

It zooms-in to the touch points on double tap. Restores default state when user double taps on max scale state.

Pinch Zoom 

ok_hand

Zoom in and out with two finger.

Free Mode love_you_gesture

You can crop your image in free mode. In any size.

Aspect Ratio Mode

iphone

Enhanced aspect ratio mode will help you while cropping. Aspect ratio will be fixed while you play with cropper. So for your social media apps, it will help you to crop in fixed size (instagram, facebook, twitter, 16:9, 1:2, 3:2 and more..)

Size Displayer keycap_ten

While you scale your image, size displayer indicates the bitmap size reactively. It will provide a smoother experience to the user.

Auto Centered heart_eyes

What ever you do while cropping, we center the bitmap with animation. Smoother experience for user.

Animations star2

We use animation everywhere in this cropper. User zoomed-out too much? We zoom back in with animation. User scrolled image out of borders? We scroll it back with animation.

Steps for using Croppy

Step 1: Installation

First install Croppy from jitpack:

allprojects {
     repositories {
    ...
    maven { url 'https://jitpack.io' }
     }
}
dependencies {
      implementation 'com.github.lyrebirdstudio:Croppy:0.2'
}

Step 2: Basic usage

Croppy is very simple to use. You just need to start it:

//Start croppy (source uri is the original image.)
val cropRequest = CropRequest.Auto(sourceUri = uri, requestCode = 101)
Croppy.start(this, cropRequest)

Then listen to results:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
      super.onActivityResult(requestCode, resultCode, data)
      if (requestCode == 101) {
           imageview.setImageURI(data.data)
     }
}

Step 3: Custom Usage

For more advanced usage you can for example save the cropped result in the external storage:

val externalCropRequest = CropRequest.Auto(sourceUri = uri, requestCode = RC_CROP_IMAGE)

You can also save it in the cache:

val cacheCropRequest = CropRequest.Auto(
     sourceUri = uri,
     requestCode = RC_CROP_IMAGE,
     storageType = StorageType.CACHE
)

You can also specify a custom destination for the cropped image:

val destinationUri = ...
val manuelCropRequest = CropRequest.Manual(
    sourceUri = uri,
    destinationUri = destinationUri,
    requestCode = RC_CROP_IMAGE
)

If you want to exclude some specific aspect ratio from bottom aspect ratio list view.

val excludeAspectRatiosCropRequest = CropRequest.Manual(
    sourceUri = uri,
    destinationUri = destinationUri,
    requestCode = RC_CROP_IMAGE,
    excludedAspectRatios = arrayListOf(AspectRatio.ASPECT_FREE)
)

If you want to give specific theme as accent color.

val themeCropRequest = CropRequest.Manual(
    sourceUri = uri,
    destinationUri = destinationUri,
    requestCode = RC_CROP_IMAGE,
    croppyTheme = CroppyTheme(R.color.blue)
)

Ultimately you have to start croppy:

//Start croppy with your custom request.
Croppy.start(this, cropRequest)

Demo

Here is the demo:

Links

  1. Download the example here.
  2. Follow the author here.

BEFORE YOU GO

YOU'VE BEEN SELECTED FOR A GIFT

Thanks for stopping by. My name is Oclemy(Clement Ochieng) and we have selected you as a recipient of a GIFT you may like ! Together with Skillshare we are offering you PROJECTS and 1000s of PREMIUM COURSES at Skillshare for FREE for 1 MONTH. To be eligible all you need is by sign up right now using my profile .

Related Examples

Leave a Reply

Your email address will not be published. Required fields are marked *

*

code