Xamarin Binding Library for Yalantis uCrop library
uCrop - Image Cropping Library for Android
For a working implementation, please have a look at the Sample Project - sample
Include the library via nuget
Install-Package Naxam.uCrop.Droid
Add UCropActivity into your AndroidManifest.xml
<activity
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"></activity>
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.
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) {
if (resultCode == Result.Ok && requestCode == UCrop.RequestCrop) {
Uri resultUri = UCrop.GetOutput(data);
} else if (resultCode == UCrop.ResultError) {
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:
This binding is licensed under the MIT license, but the native Java library is license under the Apache License by Yalantis.
Copyright 2017, Yalantis
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.