Code Monkey home page Code Monkey logo

imagecropper's Introduction

MAUI / Xamarin ImageCropper

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 Nuget ✖️ ✖️
Xamarin Nuget ✖️ ✖️
.NET Nuget ✖️ ✖️

Powered By:

Another platforms:

Currently Windows and MacCatalyst are not supported, but your PRs are welcome

Mono setup:

Android:

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" />

iOS:

No extra actions required

.NET setup:

Android:

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" />

iOS:

No extra actions required

MAUI setup:

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)

Android:

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" />

iOS:

No extra actions required

Example of usage:

Note: in MAUI use Cropper class instead of ImageCropper
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
    }
});

imagecropper's People

Contributors

alex-dobrynin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.