Simple crossplatform MAUI / Xamarin image cropper, you can use it in Xamarin.Forms, Xamarin native and MAUI. Also compatible with .NET 7
Supported platforms | Nuget | Android | iOS | Windows | MacCatalyst |
---|---|---|---|---|---|
MAUI | ✅ | ✅ | ✖️ | ✖️ | |
Xamarin | ✅ | ✅ | ✖️ | ✖️ | |
.NET | ✅ | ✅ | ✖️ | ✖️ |
- Mono Android - uses ArturHub's Android-Image-Cropper
- .NET / MAUI Android - uses CanHub's Android-Image-Cropper
- iOS - uses uses Tim Oliver's TOCropViewController
Currently Windows and MacCatalyst are not supported, but your PRs are welcome
It uses Plugin.CurrentActivity under the hood, so don't forget to initialize it in your MainActivity.cs's OnCreate method:
Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle);
Also, you need to add OnActivityResult handler:
protected override void OnActivityResult(int requestCode, Result resultCode, Intent intent)
{
base.OnActivityResult(requestCode, resultCode, intent);
Plugin.Maui.ImageCropper.Platform.Droid.OnActivityResult(requestCode, resultCode, intent);
}
Don't forget to add this row into your AndroidManifest.xml file application tag:
<activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />
No extra actions required
All you need is to initialize it in your MainActivity.cs's OnCreate method:
Plugin.Maui.ImageCropper.Platform.Droid.Init(this);
Don't forget to add this row into your AndroidManifest.xml file application tag:
<activity android:name="com.canhub.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />
No extra actions required
To use it in MAUI you should call UseImageCropper()
method from Plugin.Maui.ImageCropper
namespace.
Also there is another overload which allows you to register ImageCropper instance in services and then use it with DI
UseImageCropper(registerInterface: true)
Don't forget to add this row into your AndroidManifest.xml file application tag:
<activity android:name="com.canhub.cropper.CropImageActivity" android:theme="@style/Base.Theme.AppCompat" />
No extra actions required
await ImageCropper.Current.Crop(new CropSettings()
{
AspectRatioX = 1,
AspectRatioY = 1,
CropShape = CropSettings.CropShapeType.Rectangle
}, imageFilePath).ContinueWith(t =>
{
if (t.IsFaulted)
{
var ex = t.Exception;
//alert user
}
else if (t.IsCanceled)
{
//do nothing
}
else if (t.IsCompletedSuccessfully)
{
var result = t.Result;
//do smth with result
}
});