Image Cropping Library for Android

Overview

Croppy

Basic Usage

//Start croppy (source uri is the original image.)
val cropRequest = CropRequest.Auto(sourceUri = uri, requestCode = 101)
Croppy.start(this, cropRequest)
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
      super.onActivityResult(requestCode, resultCode, data)
      if (requestCode == 101) {
           imageview.setImageURI(data.data)
     }
}

Custom Usage

Create cropped image result in external storage

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

Create cropped image result in cache storage

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

If you want to create destination file manually

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)
)
//Start croppy with your custom request.
Croppy.start(this, cropRequest)

Demo

Features

Double tap focus πŸ‘† πŸ‘†

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

Pinch Zoom πŸ‘Œ

Zoom in and out with two finger.

Free Mode 🀟

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

Aspect Ratio Mode πŸ“±

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 πŸ”Ÿ

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

Auto Centered 😍

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

Animations 🌟

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.

Setup

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

License

Copyright 2019 Lyrebird Studio.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Oriented Images Should Rotate Before Loading

    Oriented Images Should Rotate Before Loading

    After taking a photo from my LG G7 and starting Croppy from the file Uri, CroppyActivity started with the image rotated.

    You may consider checking ExifInterface orientation before loading bitmap.

    Sample code in Java :

    Bitmap rotateBitmap(@NonNull String src, Bitmap bitmap) {
                int orientation;
    
                try {
                    orientation = getExifOrientation(src);
                } catch (IOException e) {
                    e.printStackTrace();
                    return bitmap;
                }
    
                Matrix matrix = new Matrix();
    
                switch (orientation) {
                    case ExifInterface.ORIENTATION_FLIP_HORIZONTAL:
                        matrix.setScale(-1, 1);
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_180:
                        matrix.setRotate(180);
                        break;
                    case ExifInterface.ORIENTATION_FLIP_VERTICAL:
                        matrix.setRotate(180);
                        matrix.postScale(-1, 1);
                        break;
                    case ExifInterface.ORIENTATION_TRANSPOSE:
                        matrix.setRotate(90);
                        matrix.postScale(-1, 1);
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_90:
                        matrix.setRotate(90);
                        break;
                    case ExifInterface.ORIENTATION_TRANSVERSE:
                        matrix.setRotate(-90);
                        matrix.postScale(-1, 1);
                        break;
                    case ExifInterface.ORIENTATION_ROTATE_270:
                        matrix.setRotate(-90);
                        break;
                    default:
                        return bitmap;
                }
    
                try {
                    Bitmap oriented = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
                    bitmap.recycle();
                    return oriented;
                } catch (OutOfMemoryError e) {
                    e.printStackTrace();
                    return null;
                }
            }
    
    private int getExifOrientation(@NonNull String src) throws IOException {
                DebugLog.write();
                ExifInterface exifInterface = new ExifInterface(src);
                return exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
            }
    
    opened by titanwalking 1
  • The  public function name  `Manuel` is spelled incorrectly

    The public function name `Manuel` is spelled incorrectly

    Here is the function in source code: https://github.com/lyrebirdstudio/Croppy/blob/0bd49dfa62b4b2e770cb2efc499f6ee625842ee8/croppylib/src/main/java/com/lyrebirdstudio/croppylib/main/CropRequest.kt#L18

    I believe it was meant to be Manual.

    I don't thing it is a problem, but the meaning implied is incorrect. This is also referenced in the Readme file.

    opened by nisrulz 1
  • Problem:

    Problem: "A resource Failed to Call Close"

    Hi I am trying the most basic version of your app The Croppy editing app will load. however once i Click the "Tick" button on the Croppy App. it just closes with a "W/System: A resource failed to call close. " I couldnt get any result back probably because of that. Any idea why this could happen?

    ` override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data)

        when(requestCode){
            1->{
                if (resultCode== Activity.RESULT_OK&&data!=null)
                {
                    imageURI_1= data.data!!
                    val cropRequest=CropRequest.Auto(data.data!!,101)
                    Log.d(TAG,"Start Croppy Activity")
                    Croppy.start(mActivity,cropRequest)
                }
            }
            
            101->{
                Log.d(TAG,"Get Crop Result Back")
                imagebutton_1.setImageURI(data!!.data)
            }
        }
    }
    

    `

    opened by haroic1997 0
  • Sum efforts??? Using another Android Crop Image

    Sum efforts??? Using another Android Crop Image

    Hey @iammert amazing work here!

    Not sure how are you doing, but how would you feel if we put our efforts together for a same unique android Library?

    Last November I handover a code from arthurHub because was not maintained since 2018

    On Jan I had 1k downloads. Today we hit 4.1k

    What you think? :)

    The lib: https://github.com/CanHub/Android-Image-Cropper

    opened by Canato 0
  • Crash if no databinding enabled in project

    Crash if no databinding enabled in project

    Crash when starting Croppy if the project doesn't have databinding added in gradle.

    Croppy.start(this, CropRequest.Auto(bitmapUri, code))
    
    FATAL EXCEPTION: main
        java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/databinding/DataBinderMapperImpl;
            at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
            at androidx.databinding.DataBindingUtil.setContentView(DataBindingUtil.java:284)
            at com.lyrebirdstudio.croppylib.main.CroppyActivity.onCreate(CroppyActivity.kt:23)
            at android.app.Activity.performCreate(Activity.java:7963)
            at android.app.Activity.performCreate(Activity.java:7952)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3629)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3806)
            at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
            at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
            at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2267)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:237)
            at android.app.ActivityThread.main(ActivityThread.java:8167)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100)
    
    opened by Dimezis 2
Releases(0.2)
Owner
Lyrebird Studio
Lyrebird Studio
Image Cropping Library for Android

Image Cropping Library for Android

Lyrebird Studio 1.1k Dec 30, 2022
Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap

Image cropping library written with Jetpack Compose with other Composables such as ImageWithConstraints scales Bitmap it displays and returns position and bounds of Bitmap and ImageWithThumbnail to display thumbnail of the image on selected corner.

Smart Tool Factory 9 Jul 27, 2022
Android widget for cropping and rotating an image.

Cropper The Cropper is an image cropping tool. It provides a way to set an image in XML and programmatically, and displays a resizable crop window on

Edmodo 2.9k Nov 14, 2022
Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image selection.

Awesome Image Picker Awesome Image Picker library will pick images/gifs with beautiful interface. Supports image or gif, Single and Multiple Image sel

Prabhakar Thota 162 Sep 13, 2022
Android library project for cropping images

I guess people are just cropping out all the sadness An Android library project that provides a simple image cropping Activity, based on code from AOS

Jamie McDonald 4.5k Jan 7, 2023
This is an Image slider with swipes, Here we used Volley to Image load URL's from JSON! Here we make it very easy way to load images from Internet and We customized the description font style(OpenSans).

ImageSliderWithSwipes This is an Image slider with swipes, Here we used Volley to load URL's from JSON! Here we make it very easy way to load images f

Prabhakar Thota 44 May 31, 2021
An android image compression library.

Compressor Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller

Zetra 6.7k Dec 31, 2022
Customizable Android full screen image viewer for Fresco library supporting "pinch to zoom" and "swipe to dismiss" gestures. Made by Stfalcon

This project is no longer supported. If you're able to switch from Fresco to any other library that works with the Android's ImageView, please migrate

Stfalcon LLC 1.8k Dec 19, 2022
Dali is an image blur library for Android. It contains several modules for static blurring, live blurring and animations.

Dali Dali is an image blur library for Android. It is easy to use, fast and extensible. Dali contains several modules for either static blurring, live

Patrick Favre-Bulle 1k Dec 1, 2022
An image resizing library for Android

Resizer Inspired by zetbaitsu's Compressor, Resizer is a lightweight and easy-to-use Android library for image scaling. It allows you to resize an ima

Kakit Ho 426 Dec 22, 2022
Simple android image popup Library

Android Image Popup Show image as a popup on a click event or any event. Simply set the image as drawable and thats it!!!. And also you can set width,

Chathura Lakmal 64 Nov 15, 2022
Image loading library for Android

Image Loader Image loader library for Android. Deprecated. See Glide. Features Image transformations Automatic memory and storage caching Ability to l

Yuriy Budiyev 19 May 28, 2022
An image loading library for android.

Bilder Download Add following to your project's build.gradle allprojects { repositories { ... maven { url 'https://jitpack.io' } } }

Kshitij Sharma 4 Jan 1, 2022
An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

An Android transformation library providing a variety of image transformations for Coil, Glide, Picasso, and Fresco.

Daichi Furiya 257 Jan 2, 2023
🎨 Modern image loading library for Android. Simple by design, powerful under the hood.

Simple Image Loader Modern image loading library for Android. Simple by design, powerful under the hood. Kotlin: Simple Image Loader is Kotlin-native

Igor Solkin 8 Nov 21, 2022
A small customizable library useful to handle an gallery image pick action built-in your app. :sunrise_over_mountains::stars:

Louvre A small customizable image picker. Useful to handle an gallery image pick action built-in your app. *Images from Google Image Search Installati

AndrΓ© Mion 640 Nov 19, 2022
Library to save image locally and shows options to open and share !

Image Save and Share Library to save image locally and shows options to open and share ! Download Demo APK from HERE Kindly use the following links to

Prabhakar Thota 27 Apr 18, 2022
RoundedImageView-Library 0.9 0.0 Java To set single or multiple corners on Image Views.

RoundedImageView-Library Rounded ImageView Android Library, to set single or multiple corners on imageview. Screenshot Usage Step 1. Add the JitPack r

Dushyant Mainwal 15 Sep 2, 2020
A library for image manipulation with power of renderScript which is faster than other ordinary solutions.

Pixl is a library for image manipulation with power of renderScript which is faster than other ordinary solutions, currently it includes three basic scripts, brightness, contrast, saturation.

Jibran Iqbal 20 Jan 23, 2022