Android widget for cropping and rotating an image.

Overview

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 top of the image. Calling the method getCroppedImage() will then return the Bitmap marked by the crop window.

Developers can customize the following attributes (both via XML and programmatically):

  • appearance of guidelines in the crop window
  • whether the aspect ratio is fixed or not
  • aspect ratio (if the aspect ratio is fixed)
  • image resource

A public method to rotate the image by a specified number of degrees is also included. This can be used to provide the user with an option to fix the image orientation should Android miscalculate the intended orientation.

Supported on API Level 7 and above.

For more information, see the linked Github Wiki page.

https://github.com/edmodo/cropper/wiki

ScreenShot

Installation

build.gradle

repositories {
	mavenCentral()
}

dependencies {
  compile 'com.edmodo:cropper:1.0.1'
}

License

Copyright 2013, Edmodo, Inc.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or 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.

Contributions

We'd love for you to participate in the development of our project. Before we can accept your pull request, please sign our Individual Contributor License Agreement. It's a short form that covers our bases and makes sure you're eligible to contribute. Thank you!

http://goo.gl/gfj6Mb

Comments
  • setImageBitmap sets the image form, but the image remains blank

    setImageBitmap sets the image form, but the image remains blank

    My layout:

    <?xml version="1.0" encoding="utf-8"?>
    <com.edmodo.cropper.CropImageView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res/com.roadtrippers"
        android:id="@+id/cropImageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:aspectRatioX="1"
        app:aspectRatioY="1"
        app:fixAspectRatio="true"
        app:guidelines="onTouch" />
    

    My Activity:

    public class CropImageActivity extends BaseActivity {
    
        static final String PATH = "path";
    
        public static Intent newInstance(Context context, String imagePath) {
            return new Intent(context, CropImageActivity.class).putExtra(PATH, imagePath);
        }
    
        @InjectView(R.id.cropImageView) CropImageView cropImageView;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.crop_image);
            Bitmap decodeFile = BitmapFactory.decodeFile(getIntent().getStringExtra(PATH));
            cropImageView.setImageBitmap(decodeFile);
        }
    }
    
    opened by meoyawn 18
  • solves #21 implemented support for scaletype fitCenter

    solves #21 implemented support for scaletype fitCenter

    The ImageViewUtil#getBitmapRectFitCenterHelper is based on nomatterhoe's proposed code in ticket #21. I added some flexibility for supporting other scale types in the future and refactored related bits of code.

    [please format the code along your code style]

    opened by mediavrog 3
  • Is it possible to support selection of quadrangle?

    Is it possible to support selection of quadrangle?

    Hi,

    This is actually a feature request.

    Thanks for the great library. Currently, I am looking for a UI library which allow me to select a quadrangle from an image. The selected area may be a trapezium or trapezoid. Is it possible to update the library which allow me to get the 4 points (co-ordinations) of user selected quadrangle? What my next is to pass the four points that the users selected to my another library which allows me to perform Quadrilateral Transformation (Perspective Correction actually).

    Many thanks.

    Michael

    opened by hkultraman 3
  • Integration of Gradle and removed a png that caused a compilation error

    Integration of Gradle and removed a png that caused a compilation error

    • Integration with the new Gradle-based android build system as well as the Android Studio IDE (With the wrapper)
    • CropperSample/res/drawable-xhdpi/cheetahs.png is not considered as a png file by aapt which is not used
    • Removed a duplicated String in strings.xml
    opened by zirkome 3
  •  height must be > 0

    height must be > 0

    java.lang.IllegalArgumentException: height must be > 0

    • 3 non-project frames 1 at android.graphics.Bitmap.checkWidthHeight (Bitmap.java:393) 2 at android.graphics.Bitmap.createBitmap (Bitmap.java:696) 3 at android.graphics.Bitmap.createBitmap (Bitmap.java:665) 4 at com.edmodo.cropper.CropImageView.getCroppedImage (CropImageView.java:293) 5 at com.unsw.berrycount.activities.CameraActivity$1.onClick (CameraActivity.java:64)
    • 9 non-project frames 6 at android.view.View.performClick (View.java:5232) 7 at android.view.View$PerformClick.run (View.java:21258) 8 at android.os.Handler.handleCallback (Handler.java:739) 9 at android.os.Handler.dispatchMessage (Handler.java:95) 10 at android.os.Looper.loop (Looper.java:179) 11 at android.app.ActivityThread.main (ActivityThread.java:5650) 12 at java.lang.reflect.Method.invoke (Unknown source) 13 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:791) 14 at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:681)
    opened by skaematik 2
  • On loaded image it's 40px wide when FixedAspectRatio(true)

    On loaded image it's 40px wide when FixedAspectRatio(true)

    I use this code: bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri); cropImageView = (CropImageView) findViewById(R.id.CropImageView); cropImageView.setImageBitmap(bitmap); cropImageView.setAspectRatio(100,100); cropImageView.setFixedAspectRatio(true);

    and I get this: screenshot_2015-05-12-17-02-41

    When I turn it off - it's working normal though it's not fixed aspect (which I need). Am I doing wrong?

    opened by janswist 2
  • IllegalArgumentException in getCroppedImage

    IllegalArgumentException in getCroppedImage

    Hello, I am getting crash when I try resize cropper much to edge of screen: java.lang.IllegalArgumentException: y + height must be <= bitmap.height() at android.graphics.Bitmap.createBitmap(Bitmap.java:413) at android.graphics.Bitmap.createBitmap(Bitmap.java:383) at com.edmodo.cropper.CropImageView.getCroppedImage(CropImageView.java:357)

    opened by yuraj11 2
  • Image view Width and Height not able to change

    Image view Width and Height not able to change

    Hello,

    I want to change image view 's height and width to fill parent or match parent but not able to change

    Right now image looking very small in device..

    How can i change image view's width and height?

    I m looking for your favorable replay as soon as possible,

    opened by ankitthakkar 2
  • Updated build tools version to 19.1.0

    Updated build tools version to 19.1.0

    build failed with Android Studio 0.6.0.

    Error:The SDK Build Tools revision (19.0.1) is too low. Minimum required is 19.1.0
    

    I've fixed this incompatible issue with below modification.

    • Update Build Tools version.
    opened by cutmail 2
  • Deploy AAR to maven central

    Deploy AAR to maven central

    It would be great to just be able to say "compile 'com.edmodo.cropper:cropper:+'" in gradle and have it be able to get the library from maven central (or some other host).

    opened by TytaniumDev 2
  • Crop on the original picture

    Crop on the original picture

    Hi,

    I have a large picture and I want to crop it. I use options.inSampleSize to get a smaller bitmap and use cropper to crop it. Then I use getCroppedImage() to get the cropped bitmap and save it to file. The problems is the resolution of the output picture is much lower than the original one. Is there a way I can crop on the original picture?

    opened by gelitenight 2
  • Android 11 photo no return

    Android 11 photo no return

    Hello, developer, I like your project very much, and I have also used it in many of my projects, but I encountered a problem in the process of using it. My mobile phone updated Android 11. I selected the camera to shoot in the source selection. The camera shot well, but no content was returned to me. Please tell me what to do. Thank you

    opened by liu171641 0
  • Migrate from JCenter

    Migrate from JCenter

    Apparently JCentre will be turned off in May 2021.

    This URL has steps on how to migrate to another maven repo:

    https://jeroenmols.com/blog/2021/02/04/migratingjcenter/

    opened by Taskmaster132 0
  • Crash on android gradle plugin 3.0.1 version

    Crash on android gradle plugin 3.0.1 version

    Hi, first of all thank you for sharing your library, it has saved me a lot of implementation time. I'm using the CropImageView like this:

     <com.edmodo.cropper.CropImageView
            android:id="@+id/image"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:layout_below="@id/toolbar_layout"
            android:layout_marginTop="20dp"
            android:layout_marginBottom="20dp"
            cropper:fixAspectRatio="true"
            cropper:scaleType="fitCenter" />
    

    and with android gradle plugin version 2.3.3 i've never had problems, but since i want to update it, now when i try to show that view the app crash with this message:

    03-15 11:19:46.057 5476-5476/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                     Process: com.mangomobi.tuttodanza, PID: 5476
                                                     java.lang.RuntimeException: Unable to resume activity {com.mangomobi.tuttodanza/com.mangomobi.showtime.app.MainActivity}: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.edmodo.cropper.CropImageView
                                                         at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3844)
                                                         at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3885)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                         at android.os.Looper.loop(Looper.java:154)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
                                                      Caused by: android.view.InflateException: Binary XML file line #15: Binary XML file line #15: Error inflating class com.edmodo.cropper.CropImageView
                                                      Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class com.edmodo.cropper.CropImageView
                                                      Caused by: java.lang.reflect.InvocationTargetException
                                                         at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                         at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                         at android.view.LayoutInflater.createView(LayoutInflater.java:652)
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
                                                         at com.mangomobi.showtime.module.user.view.CropPictureView.onCreateView(CropPictureView.java:74)
                                                         at android.support.v4.app.Fragment.performCreateView(Fragment.java:2343)
                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1421)
                                                         at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1752)
                                                         at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1821)
                                                         at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                                                         at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2595)
                                                         at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2382)
                                                         at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2337)
                                                         at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2244)
                                                         at android.support.v4.app.FragmentController.execPendingActions(FragmentController.java:382)
                                                         at android.support.v4.app.FragmentActivity.onResume(FragmentActivity.java:488)
                                                         at com.mangomobi.showtime.app.MainActivity.onResume(MainActivity.java:309)
                                                         at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1277)
                                                         at android.app.Activity.performResume(Activity.java:7101)
                                                         at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3821)
                                                         at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3885)
                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                         at android.os.Looper.loop(Looper.java:154)
                                                         at android.app.ActivityThread.main(ActivityThread.java:6776)
                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)
                                                      Caused by: java.lang.IllegalArgumentException: Cannot set aspect ratio value to a number less than or equal to 0.
                                                         at com.edmodo.cropper.cropwindow.CropOverlayView.setInitialAttributeValues(CropOverlayView.java:331)
    03-15 11:19:46.057 5476-5476/? E/AndroidRuntime:     at com.edmodo.cropper.CropImageView.init(CropImageView.java:490)
                                                         at com.edmodo.cropper.CropImageView.<init>(CropImageView.java:101)
    

    Notice that by creating a class that has the exact source code of your CropImageView and putting it in my sources the crash doesn't happen, this is why i think is related to the gradle plugin update.

    Also, the dependency i have is:

    implementation "com.githang:com.edmodo.cropper:1.0.2"

    Any suggestion/fix/workaround?

    Thanks

    opened by nlasagni 1
  • Add multiple Intent in Same activity

    Add multiple Intent in Same activity

    I want to call multiple intent for crop image. How will I handle Intent onActivityResult. because request code is same.

    CropImage.activity(Uri.parse(uri.toString()))
                                        .setAspectRatio(500, 500)
                                        // .setMaxCropResultSize(600,600)
                                        .setFixAspectRatio(true)
                                        //.setOutputCompressQuality(70)
                                        .setGuidelines(CropImageView.Guidelines.ON)
    
                                        .start(WebActivity.this);
    
    opened by AmanChugh 0
Owner
Edmodo
Edmodo
Image Cropping Library for Android, optimised for Camera / Gallery.

Image Cropping Library for Android, optimised for Camera / Gallery.

CanHub 722 Sep 25, 2022
Image Cropping Library for Android

Image Cropping Library for Android

Lyrebird Studio 1k Sep 21, 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
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 Sep 17, 2022
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
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
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 Sep 26, 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 Sep 29, 2022
An Android project containing image recognition and object detection models.

An Android project containing image recognition and object detection models. Users can input images into the deep learning model by taking photos, opening photo albums, and real-time previews on the Android side. After the calculation on the Android side is completed, the model will output the prediction result and show it to the user.

null 6 Feb 26, 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 250 Sep 16, 2022
Pixel Boom is a Java-based Android software, featuring image super-resolution and colorization

Pixel Boom is a Java-based Android software, featuring image super-resolution and colorization.

Zaitian 1 Jul 3, 2022
Add curve at bottom of image views and relative layouts.

Crescento Android library that adds a curve at the below of image views and relative layouts. CrescentoImageView and CrescentoContainer are the image

Shivam Satija 1.3k Sep 28, 2022
Add curve at bottom of image views and relative layouts.

Crescento Android library that adds a curve at the below of image views and relative layouts. CrescentoImageView and CrescentoContainer are the image

Shivam Satija 1.3k Mar 24, 2021
Auto Scrolling Image Pager with Pager Indicator and Text

AutoImageFlipper Auto Scrolling Image Pager with Pager Indicator and Text Note: It works only on Apps which are using AndroidX dependencies, if you're

Shahbaz Hussain 106 Mar 25, 2022
Phimp.me Android Phimp.me is an Android image editor app

Phimp.me Android Phimp.me is an Android image editor app that aims to replace proprietary photographing and image apps on smart phones. It offers feat

FOSSASIA 2.5k Sep 27, 2022
some android image filters

android-image-filter some android image filters in some filter, I use NDK to implement to make it more efficient Setup Install Android NDK and properl

RagnarokStack 624 Sep 27, 2022
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.6k Oct 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 Sep 26, 2022