Convert Figma logo to code with AI

jdamcd logoandroid-crop

Android library project for cropping images

4,537
1,075
4,537
132

Top Related Projects

11,849

Image Cropping Library for Android

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

A simple image cropping library for Android.

Quick Overview

Android-crop is an Android library project for cropping images. It provides a simple image cropping activity, based on code from AOSP (Android Open Source Project). This library simplifies the process of adding image cropping functionality to Android applications.

Pros

  • Easy integration into existing Android projects
  • Customizable UI elements and crop window
  • Supports both programmatic and XML-based configuration
  • Lightweight and efficient implementation

Cons

  • Limited to rectangular crop shapes
  • Lacks advanced features like perspective correction or rotation
  • Not actively maintained (last update was in 2017)
  • May require additional work to integrate with modern Android architecture components

Code Examples

  1. Starting the crop activity:
val intent = Intent(this, CropImageActivity::class.java)
intent.putExtra(CropImageActivity.EXTRA_IMAGE_PATH, imagePath)
startActivityForResult(intent, REQUEST_CROP)
  1. Handling the cropped image result:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    if (requestCode == REQUEST_CROP && resultCode == Activity.RESULT_OK) {
        val croppedImage = data?.getParcelableExtra<Bitmap>(CropImageActivity.EXTRA_CROPPED_IMAGE)
        imageView.setImageBitmap(croppedImage)
    }
}
  1. Customizing crop window appearance:
val intent = Intent(this, CropImageActivity::class.java)
intent.putExtra(CropImageActivity.EXTRA_IMAGE_PATH, imagePath)
intent.putExtra(CropImageActivity.EXTRA_ASPECT_X, 16)
intent.putExtra(CropImageActivity.EXTRA_ASPECT_Y, 9)
intent.putExtra(CropImageActivity.EXTRA_MAX_X, 1024)
intent.putExtra(CropImageActivity.EXTRA_MAX_Y, 576)
startActivityForResult(intent, REQUEST_CROP)

Getting Started

  1. Add the library to your project's build.gradle:
dependencies {
    implementation 'com.soundcloud.android:android-crop:1.0.1@aar'
}
  1. Add the CropImageActivity to your AndroidManifest.xml:
<activity android:name="com.soundcloud.android.crop.CropImageActivity" />
  1. Start the crop activity and handle the result as shown in the code examples above.

Competitor Comparisons

11,849

Image Cropping Library for Android

Pros of uCrop

  • More feature-rich with advanced customization options
  • Supports both image cropping and rotating
  • Actively maintained with regular updates

Cons of uCrop

  • Larger library size, potentially increasing app size
  • Steeper learning curve due to more complex API

Code Comparison

android-crop:

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

uCrop:

UCrop.of(sourceUri, destinationUri)
    .withAspectRatio(1, 1)
    .start(activity);

Both libraries offer simple one-line implementations for basic cropping. However, uCrop provides more options for customization:

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

Summary

uCrop offers more features and customization options compared to android-crop, making it suitable for advanced use cases. However, this comes at the cost of a larger library size and potentially more complex implementation. android-crop is simpler and more lightweight but lacks some advanced features. The choice between the two depends on the specific requirements of your project and the level of customization needed.

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

Pros of Android-Image-Cropper

  • More actively maintained with recent updates
  • Offers a wider range of customization options
  • Supports both bitmap and URI image sources

Cons of Android-Image-Cropper

  • Larger library size, potentially increasing app size
  • More complex implementation due to additional 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 provides more customization options in its builder pattern, while android-crop offers a simpler, more concise API for basic cropping tasks. The former allows for more fine-grained control over the cropping process, including guidelines and aspect ratio settings, whereas the latter focuses on simplicity for common use cases like square cropping.

Android-Image-Cropper is better suited for projects requiring advanced image cropping features and customization, while android-crop may be preferable for simpler implementations or projects with stricter size constraints.

A simple image cropping library for Android.

Pros of SimpleCropView

  • More customizable with additional features like circular cropping and dynamic aspect ratio
  • Actively maintained with recent updates and bug fixes
  • Better performance and smoother user experience

Cons of SimpleCropView

  • Larger library size due to additional features
  • Steeper learning curve for implementation compared to android-crop

Code Comparison

SimpleCropView:

mCropView = findViewById(R.id.cropImageView);
mCropView.setAspectRatio(1, 1);
mCropView.setCropMode(CropImageView.CropMode.CIRCLE);
mCropView.setImageBitmap(bitmap);

android-crop:

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

SimpleCropView offers more granular control over the cropping process, allowing developers to customize various aspects of the cropping view. android-crop provides a simpler, more straightforward implementation but with fewer customization options.

Both libraries serve the purpose of image cropping in Android applications, but SimpleCropView is more feature-rich and actively maintained, making it a better choice for projects requiring advanced cropping functionality. However, for simpler use cases, android-crop may be sufficient and easier to implement.

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

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 AOSP.

Deprecated! This project is not maintained. If it doesn't meet your needs as is, consider creating a fork or picking from these alternatives.

maven central changelog

Features

  • Gradle build & AAR
  • Modern UI
  • Backwards compatible to SDK 10
  • Simple builder for configuration
  • Example project

Usage

First, declare CropImageActivity in your manifest file:

<activity android:name="com.soundcloud.android.crop.CropImageActivity" />

Crop

Crop.of(inputUri, outputUri).asSquare().start(activity)

Listen for the result of the crop (see example project if you want to do some error handling):

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent result) {
    if (requestCode == Crop.REQUEST_CROP && resultCode == RESULT_OK) {
        doSomethingWithCroppedImage(outputUri);
    }
}

Some attributes are provided to customise the crop screen. See the example project theme.

Pick

The library provides a utility method to start an image picker:

Crop.pickImage(activity)

Dependency

The AAR is published on Maven Central:

compile 'com.soundcloud.android:android-crop:1.0.1@aar'

How does it look?

android-crop screenshot

License

This project is based on the AOSP camera image cropper via android-cropimage.

Copyright 2016 SoundCloud

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.