stormlion227 / ImageCropper.Forms

Xamarin.Forms plugin to crop and rotate photos.
MIT License
88 stars 59 forks source link
android crop-image cropper image-cropper image-editing image-rotate ios netstandard20 nuget-package plugin rotate-image xamarin-forms

ImageCropper.Forms

Xamarin.Forms plugin to crop and rotate photos.

NuGet

Supports Android and iOS.

Features

Screen-Shots

Android

Crop/Rotate image(Rectangle/Android) Crop/Rotate image(Circle/Android)

iOS

Crop/Rotate image(Rectangle/iOS) Crop/Rotate image(Circle/iOS)

Setup

Android

Add the following to your AndroidManifest.xml inside the tags:

    <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity"
              android:theme="@style/Base.Theme.AppCompat"/> 

In MainActivity.cs file:

    Stormlion.ImageCropper.Droid.Platform.Init();

    global::Xamarin.Forms.Forms.Init(this, bundle);
    protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
    {
        base.OnActivityResult(requestCode, resultCode, data);

        Stormlion.ImageCropper.Droid.Platform.OnActivityResult(requestCode, resultCode, data);
    }

iOS

In AppDelegate.cs file:

    Stormlion.ImageCropper.iOS.Platform.Init();

Usage

Show ImageCropper page.

    new ImageCropper()
    {
        Success = (imageFile) =>
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                imageView.Source = ImageSource.FromFile(imageFile);
            });
        }
    }.Show(this);

Show it with additional parameters.

    new ImageCropper()
    {
        PageTitle = "Test Title",
        AspectRatioX = 1,
        AspectRatioY = 1,
    CropShape = ImageCropper.CropShapeType.Oval,
    SelectSourceTitle = "Select source",
    TakePhotoTitle = "Take Photo",
    PhotoLibraryTitle = "Photo Library",
    CancelButtonTitle = "Cancel",
        Success = (imageFile) =>
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                imageView.Source = ImageSource.FromFile(imageFile);
            });
        }
    }.Show(this);

Show it with a image

    new ImageCropper()
    {
        Success = (imageFile) =>
        {
            Device.BeginInvokeOnMainThread(() =>
            {
                imageView.Source = ImageSource.FromFile(imageFile);
            });
        }
    }.Show(this, imageFileName);

Get byte[] from image file

var imageBytes = ImageCropper.Current.GetBytes(imageFile: imageFile);

Properties

Contributions

Contributions are welcome!