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
这是什么东西?uCrop 是 Yalantis 开发的一个 Android 开源图片裁剪库,旨在为应用提供极致且灵活的照片裁剪体验。
这是一个现成的裁剪应用,还是需要嵌入我自己应用里的库?它是一个嵌入到 Android 应用里使用的库:你通过 builder 风格的配置启动 UCropActivity,并在回调中接收裁剪结果。裁剪在原生代码中执行以保证画质,大约会给 APK 增加 1.5 MB 的体积。
怎么把它加到我的项目里?四个步骤:把该库作为本地 library 项目引入,在 AndroidManifest.xml 中添加 UCropActivity,注册接收结果的回调,再用 builder 模式进行配置。另外还建议添加一段可选的 ProGuard 配置。
它支持哪些 Android 版本?当前版本需要 Android Lollipop 5.0+(API 21);2.2.11 及更早的版本最低支持 Android ICS 4.0+(API 14)。2.2.11 版本目标为 SDK 36,并加入了对 16 KB 内存页和全屏(edge-to-edge)界面的支持。
裁剪后的图片能保存成哪些格式?只支持 JPEG 和 PNG——不支持 WebP。JPEG 的质量可以在 0 到 100 之间设置,而无损的 PNG 则会忽略质量设置。
用户裁剪照片时,照片会被发送到别处吗?不会——根据 README 的说明,该软件不会向 Yalantis 或第三方收集、存储或传输数据,所有内容都保留在设备本地。
在商业应用里可以免费使用吗?可以。uCrop 采用 Apache License 2.0 许可证,可以免费使用,包括在商业应用中。
我必须把用户限制在固定的宽高比上吗?不必——如果你不调用 withAspectRatio(x, y),用户可以自行选择比例,'Freestyle' 模式还允许他们通过拖动裁剪框的四个角来自由调整大小。
裁剪界面上有哪些可以调整的地方?通过 UCrop.Options 可以设置:压缩格式和质量、同时启用的手势、解码位图的最大尺寸、裁剪框和辅助线的颜色/宽度/数量、椭圆形裁剪区域,以及 Toolbar、StatusBar 和激活控件的界面颜色。
可以直接从网址裁剪图片吗?可以——从 1.4 版本起,uCrop 支持传入 HTTP(s) URI,加载和裁剪都在后台线程中进行,处理位图期间会显示加载提示。
它能裁剪大尺寸照片而不损失画质吗?可以——从 2.0 版本起,裁剪在原生层面完成,能够处理 16MP 和 32MP 这类高分辨率照片,并且 EXIF 信息会被复制到裁剪结果中。
Creator
Yalantis
Size
63.5 MB
Stars
12.1K
Age
10y
Commits · 90 Days