Convert Figma logo to code with AI

ArthurHub logoAndroid-Image-Cropper

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

6,389
1,362
6,389
362

Top Related Projects

11,849

Image Cropping Library for Android

Android library project for cropping images

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

Android's TextView that can expand/collapse like the Google Play's app description

A simple image cropping library for Android.

Quick Overview

Android-Image-Cropper is an Android library for image cropping functionality. It provides a customizable UI for selecting and cropping images within Android applications, offering features like zooming, rotating, and multi-touch gestures for precise image manipulation.

Pros

  • Easy integration with Android projects
  • Highly customizable UI and crop window
  • Supports both programmatic and XML-based implementation
  • Handles various image sources (camera, gallery, file)

Cons

  • Limited documentation for advanced use cases
  • Some reported issues with memory management in older versions
  • Occasional conflicts with other image processing libraries
  • Lack of recent updates (as of the last check)

Code Examples

  1. Basic implementation in an Activity:
class CropActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_crop)

        CropImage.activity()
            .setGuidelines(CropImageView.Guidelines.ON)
            .start(this)
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
            val result = CropImage.getActivityResult(data)
            if (resultCode == RESULT_OK) {
                val resultUri = result.uri
                // Use the cropped image URI
            } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
                val error = result.error
                // Handle the error
            }
        }
    }
}
  1. Customizing crop options:
CropImage.activity(imageUri)
    .setAspectRatio(1, 1)
    .setRequestedSize(300, 300)
    .setCropShape(CropImageView.CropShape.OVAL)
    .start(this)
  1. Using CropImageView in XML:
<com.theartofdev.edmodo.cropper.CropImageView
    android:id="@+id/cropImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:cropGuidelines="on"
    app:cropScaleType="centerInside"
    app:cropShape="rectangle" />

Getting Started

  1. Add the dependency to your app's build.gradle:
dependencies {
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}
  1. Add the following to your AndroidManifest.xml:
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
          android:theme="@style/Base.Theme.AppCompat"/>
  1. Implement image cropping in your activity:
CropImage.activity().start(this)
  1. Handle the result in onActivityResult as shown in the code examples above.

Competitor Comparisons

11,849

Image Cropping Library for Android

Pros of uCrop

  • More customizable UI with extensive theming options
  • Supports both image cropping and rotation in a single interface
  • Offers built-in image compression functionality

Cons of uCrop

  • Larger library size, which may impact app size
  • Steeper learning curve due to more complex API

Code Comparison

Android-Image-Cropper:

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .start(this);

uCrop:

UCrop.of(sourceUri, destinationUri)
    .withAspectRatio(16, 9)
    .withMaxResultSize(maxWidth, maxHeight)
    .start(this);

Both libraries offer simple implementation, but uCrop provides more customization options in its builder pattern. Android-Image-Cropper focuses on a straightforward approach, while uCrop allows for more fine-tuned control over the cropping process.

uCrop excels in UI customization and additional features like rotation and compression, making it suitable for projects requiring a polished, feature-rich image editing experience. Android-Image-Cropper, on the other hand, is more lightweight and easier to implement, making it ideal for simpler use cases or projects where minimizing app size is crucial.

Android library project for cropping images

Pros of android-crop

  • Lightweight and simple to use
  • Supports both square and free-form cropping
  • Easy integration with existing Android projects

Cons of android-crop

  • Less actively maintained (last update in 2017)
  • Fewer customization options for the cropping interface
  • Limited support for newer Android versions and features

Code Comparison

Android-Image-Cropper:

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .setAspectRatio(1, 1)
    .start(this);

android-crop:

Crop.of(sourceUri, destinationUri).asSquare().start(activity);

Android-Image-Cropper offers more built-in customization options in its initialization, while android-crop provides a more concise API for basic cropping tasks.

Android-Image-Cropper generally provides more features and flexibility, including:

  • Customizable overlay and guidelines
  • Rotation and flipping options
  • Support for various image sources (camera, gallery, file)

android-crop is simpler to implement for basic cropping needs but lacks some advanced features and customization options available in Android-Image-Cropper.

Both libraries serve the purpose of image cropping in Android applications, but Android-Image-Cropper is more feature-rich and actively maintained, making it a better choice for projects requiring extensive cropping functionality or long-term support.

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

Pros of Android-Image-Cropper (CanHub)

  • More actively maintained with recent updates and bug fixes
  • Improved compatibility with newer Android versions and libraries
  • Enhanced performance and stability

Cons of Android-Image-Cropper (CanHub)

  • Potential breaking changes for users migrating from the original repository
  • May have a smaller community and fewer resources compared to the original

Code Comparison

Android-Image-Cropper (ArthurHub):

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .start(this)

Android-Image-Cropper (CanHub):

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .setCropShape(CropImageView.CropShape.RECTANGLE)
    .start(this)

The CanHub version offers additional customization options, such as setting the crop shape, while maintaining compatibility with the original API.

Both libraries provide similar core functionality for image cropping in Android applications. The CanHub fork aims to continue development and address issues that may have been left unresolved in the original repository. Users should consider their specific requirements and the level of community support when choosing between the two options.

Android's TextView that can expand/collapse like the Google Play's app description

Pros of ExpandableTextView

  • Focused on text expansion functionality, making it more lightweight and specialized
  • Provides smooth animation for expanding/collapsing text
  • Easy to implement with minimal configuration required

Cons of ExpandableTextView

  • Limited to text-based content, unlike Android-Image-Cropper's image manipulation capabilities
  • Less actively maintained, with fewer recent updates and contributions
  • Smaller community and fewer stars on GitHub, potentially indicating less widespread adoption

Code Comparison

ExpandableTextView implementation:

ExpandableTextView expandableTextView = findViewById(R.id.expandable_text_view);
expandableTextView.setText(longText);
expandableTextView.setOnExpandStateChangeListener(new ExpandableTextView.OnExpandStateChangeListener() {
    @Override
    public void onExpandStateChanged(TextView textView, boolean isExpanded) {
        // Handle expand/collapse state change
    }
});

Android-Image-Cropper implementation:

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .setAspectRatio(1, 1)
    .start(this);

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {
            Uri resultUri = result.getUri();
            // Use the cropped image
        }
    }
}

A simple image cropping library for Android.

Pros of SimpleCropView

  • Simpler API and easier to implement for basic cropping needs
  • Lightweight and has fewer dependencies
  • Supports both rectangle and oval crop shapes out of the box

Cons of SimpleCropView

  • Less customizable compared to Android-Image-Cropper
  • Fewer advanced features like rotation and flipping
  • Limited documentation and examples

Code Comparison

SimpleCropView implementation:

mCropView = findViewById(R.id.cropImageView);
mCropView.setImageBitmap(bitmap);
mCropView.crop(new CropCallback() {
    @Override
    public void onSuccess(Bitmap croppedBitmap) {
        // Handle cropped image
    }
});

Android-Image-Cropper implementation:

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .setAspectRatio(1, 1)
    .start(this);

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {
            Uri resultUri = result.getUri();
            // Handle cropped image
        }
    }
}

Both libraries offer image cropping functionality, but SimpleCropView provides a more straightforward approach for basic needs, while Android-Image-Cropper offers more advanced features and customization options at the cost of a slightly more complex implementation.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Android Image Cropper

:triangular_flag_on_post: The Project is NOT currently maintained :triangular_flag_on_post:

Please use CanHub's fork!

Thank everybody for using the library. It was very fun to create and a privilage to help you build awesome apps.

The same way I took an unmaintained initial implementation from edmodo, I'm happy to see CanHub taking it now.

Good luck and happy coding :octocat:



Android Arsenal Build Status

Powerful (Zoom, Rotation, Multi-Source), customizable (Shape, Limits, Style), optimized (Async, Sampling, Matrix) and simple image cropping library for Android.

Crop

Usage

For a working implementation, please have a look at the Sample Project

See GitHub Wiki for more info.

  1. Include the library
dependencies {
    api 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
}

Add permissions to manifest

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Add this line to your Proguard config file

-keep class androidx.appcompat.widget.** { *; }

Using Activity

  1. Add CropImageActivity into your AndroidManifest.xml
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
  android:theme="@style/Base.Theme.AppCompat"/> <!-- optional (needed if default theme has no action bar) -->
  1. Start CropImageActivity using builder pattern from your activity
// start picker to get image for cropping and then use the image in cropping activity
CropImage.activity()
  .setGuidelines(CropImageView.Guidelines.ON)
  .start(this);

// start cropping activity for pre-acquired image saved on the device
CropImage.activity(imageUri)
 .start(this);

// for fragment (DO NOT use `getActivity()`)
CropImage.activity()
  .start(getContext(), this);
  1. Override onActivityResult method in your activity to get crop result
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
    CropImage.ActivityResult result = CropImage.getActivityResult(data);
    if (resultCode == RESULT_OK) {
      Uri resultUri = result.getUri();
    } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
      Exception error = result.getError();
    }
  }
}

Using View

  1. Add CropImageView into your activity
<!-- Image Cropper fill the remaining available height -->
<com.theartofdev.edmodo.cropper.CropImageView
  xmlns:custom="http://schemas.android.com/apk/res-auto"
  android:id="@+id/cropImageView"
  android:layout_width="match_parent"
  android:layout_height="0dp"
  android:layout_weight="1"/>
  1. Set image to crop
cropImageView.setImageUriAsync(uri);
// or (prefer using uri for performance and better user experience)
cropImageView.setImageBitmap(bitmap);
  1. Get cropped image
// subscribe to async event using cropImageView.setOnCropImageCompleteListener(listener)
cropImageView.getCroppedImageAsync();
// or
Bitmap cropped = cropImageView.getCroppedImage();

Features

  • Built-in CropImageActivity.
  • Set cropping image as Bitmap, Resource or Android URI (Gallery, Camera, Dropbox, etc.).
  • Image rotation/flipping during cropping.
  • Auto zoom-in/out to relevant cropping area.
  • Auto rotate bitmap by image Exif data.
  • Set result image min/max limits in pixels.
  • Set initial crop window size/location.
  • Request cropped image resize to specific size.
  • Bitmap memory optimization, OOM handling (should never occur)!
  • API Level 14.
  • More..

Customizations

  • Cropping window shape: Rectangular or Oval (cube/circle by fixing aspect ratio).
  • Cropping window aspect ratio: Free, 1:1, 4:3, 16:9 or Custom.
  • Guidelines appearance: Off / Always On / Show on Toch.
  • Cropping window Border line, border corner and guidelines thickness and color.
  • Cropping background color.

For more information, see the GitHub Wiki.

Posts

Change log

2.8.0

  • Fix crash on Android O (thx @juliooa)
  • Update to support library to AndroidX (thx @mradzinski)
  • Handle failure when selecting non image file (thx @uncledoc)
  • More translations (thx @jkwiecien, @david-serrano)

2.7.0

  • Update gradle wrapper to 4.4
  • Update support library to 27.1.1 and set is statically! (thx @androideveloper)
  • Fix NPE in activity creation by tools (thx @unverbraucht)
  • More translations (thx @gwharvey, @dlackty, @JairoGeek, @shaymargolis)

See full change log.

License

Originally forked from edmodo/cropper.

Copyright 2016, Arthur Teplitzki, 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.