For a working implementation, please have a look at the Sample Project - sample
Include the library as a local library project.
allprojects {
repositories {
jcenter()
maven { url "https://jitpack.io" }
}
}
implementation 'com.github.yalantis:ucrop:2.2.8'
- lightweight general solution
implementation 'com.github.yalantis:ucrop:2.2.8-native'
- get power of the native code to preserve image quality (+ about 1.5 MB to an apk size)
Add UCropActivity into your AndroidManifest.xml
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
The uCrop configuration is created using the builder pattern.
UCrop.of(sourceUri, destinationUri)
.withAspectRatio(16, 9)
.withMaxResultSize(maxWidth, maxHeight)
.start(context);
Override onActivityResult
method and handle uCrop result.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == UCrop.REQUEST_CROP) {
final Uri resultUri = UCrop.getOutput(data);
} else if (resultCode == UCrop.RESULT_ERROR) {
final Throwable cropError = UCrop.getError(data);
}
}
You may want to add this to your PROGUARD config:
-dontwarn com.yalantis.ucrop**
-keep class com.yalantis.ucrop** { *; }
-keep interface com.yalantis.ucrop** { *; }
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:
options.setCircleDimmedLayer(true)
) crop areaImage is loaded in a background thread. Better error-handling for image decoding.
Improved EXIF data support (rotation and mirror).
Small UI updates.
Couple new things to configure.
Sample updated with the possibility to choose custom aspect ratio.
We’d be really happy if you sent us links to your projects where you use our component. Just send an email to github@yalantis.com And do let us know if you have any questions or suggestion regarding the library.
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.