uCrop README

The project's README from github.com/Yalantis/uCrop. As one markdown file: README.md.

uCrop - Image Cropping Library for Android

This project aims to provide an ultimate and flexible image cropping experience. Made in Yalantis

How We Created uCrop

Check this project on Dribbble

Usage

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

Get it on Google Play

  1. Include the library as a local library project.

    allprojects {
       repositories {
          maven { url "https://jitpack.io" }
       }
    }
    

    implementation 'com.github.yalantis:ucrop:2.2.11' - lightweight general solution

    implementation 'com.github.yalantis:ucrop:2.2.11-native' - get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)

  2. Add UCropActivity into your AndroidManifest.xml

    <activity
        android:name="com.yalantis.ucrop.UCropActivity"
        android:screenOrientation="portrait"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
    
  3. Register a callback for the uCrop result.

    private ActivityResultLauncher<Intent> activityResultLauncher =
            registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
                if (result.getResultCode() == RESULT_OK) {
                    final Uri resultUri = UCrop.getOutput(result.getData());
                } else if (result.getResultCode() == UCrop.RESULT_ERROR) {
                    final Throwable cropError = UCrop.getError(result.getData());
                }
            });
    
  4. Create the uCrop configuration using the builder pattern.

    UCrop.of(sourceUri, destinationUri)
        .withAspectRatio(16, 9)
        .withMaxResultSize(maxWidth, maxHeight)
        .start(context, activityResultLauncher);
    
  5. You may want to add this to your PROGUARD config:

    -dontwarn com.yalantis.ucrop**
    -keep class com.yalantis.ucrop** { *; }
    -keep interface com.yalantis.ucrop** { *; }
    

Customization

If you want to let your users choose crop ratio dynamically, just do not call withAspectRatio(x, y).

uCrop builder class has method withOptions(UCrop.Options options) which extends library configurations.

Currently, you can change:

Compatibility

Changelog

Version: 2.2.11

Version: 2.2.10

Version: 2.2.9

Version: 2.2.8

Version: 2.2.5

Version: 2.2.4

Version: 2.2.3

Version: 2.2.2

Version: 2.2.1

Version: 2.2

Version: 2.1

Version: 2.0

Version: 1.5

Version: 1.4

Version: 1.3

Version: 1.2

Version: 1.1

Version: 1.0

Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the library.

Apps using uCrop

License

Copyright 2017, Yalantis

Software doesn't collect, store or transfer data to Yalantis or third parties.
Emplacement of this Software is carried out locally at device.

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.

uCrop (Yalantis/uCrop)

Searching Database…

12.1K ·GitHub
What is this?uCrop is an open-source image cropping library for Android, made by Yalantis to give apps an ultimate and flexible photo cropping experience.
Is this a ready-made cropping app, or a library I embed in my own app?A library you embed in your Android app: you launch UCropActivity with a builder-style config and receive the result in a callback. Cropping runs in native code to preserve quality, adding about 1.5 MB to the APK.
How do I add it to my project?Four steps: include the library as a local library project, add UCropActivity to your AndroidManifest.xml, register a callback for the result, and configure it with the builder pattern. An optional ProGuard snippet is suggested too.
Which Android versions does it run on?Current releases need Android Lollipop 5.0+ (API 21); versions up to 2.2.11 go back to Android ICS 4.0+ (API 14). Release 2.2.11 targets SDK 36 and adds 16 KB page size and edge-to-edge UI support.
What formats can the cropped image be saved in?JPEG or PNG only — WebP is not supported. JPEG quality is configurable from 0 to 100, while lossless PNG ignores the quality setting.
Do users' photos get sent anywhere when cropping?No — per the README, the software doesn't collect, store or transfer data to Yalantis or third parties; everything stays locally on the device.
Can I use it for free in a commercial app?Yes. uCrop is licensed under the Apache License 2.0, so it is free to use, including in commercial apps.
Do I have to lock users to a fixed aspect ratio?No — if you skip withAspectRatio(x, y), users pick the ratio themselves, and a 'Freestyle' mode lets them resize the crop rectangle by dragging its corners.
What can I tweak in the crop screen?Via UCrop.Options: compression format and quality, simultaneous gestures, max decoded bitmap size, crop frame and guideline colors/width/counts, an oval crop area, and UI colors for the Toolbar, StatusBar and active controls.
Can I crop an image straight from a URL?Yes — since version 1.4 uCrop accepts HTTP(s) URIs, and both loading and cropping run in a background thread with a loader shown while the bitmap is processed.
Can it crop big photos without losing quality?Yes — since version 2.0 the crop is done natively, handling high-resolution shots like 16MP and 32MP images, and EXIF data is copied to the cropped result.
Creator
Yalantis
Size
63.5 MB
Stars
12.1K
Age
10y
Commits · 90 Days