Alex-Dobrynin / Xamarin.Controls.ImageCropper

Cross platform Xamarin library to crop and rotate images
MIT License
8 stars 2 forks source link

Sometimes stops working on Android #3

Closed AlanFloyd closed 2 years ago

AlanFloyd commented 2 years ago

I have seen that after a couple of times, the controls stops working on Android. Using the debugger, the last statement executed is the "await ImageCropper.Current.Crop(new CropSettings()", but there is no reply to IsFaulted, IsCanceled or IsCompleted. Here the code:

Device.BeginInvokeOnMainThread(async () =>
            {
                await ImageCropper.Current.Crop(new CropSettings()
                {
                    AspectRatioX = 1,
                    AspectRatioY = 1,
                    CropShape = CropSettings.CropShapeType.Rectangle
                }, PhotoPath).ContinueWith(t =>
                {
                    if (t.IsFaulted)
                    {
                        var ex = t.Exception;
                        //alert user
                    }
                    else if (t.IsCanceled)
                    {
                        var ex = t.Exception;
                        //do nothing
                    }
                    else if (t.IsCompleted)
                    {
                        var result = t.Result;
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            logo_image.Source = result;
                            is_saved = false;
                            photo_path = result;
                            lbl_initials.IsVisible = false;
                            logo_image.IsVisible = true;
                        });
                    }
                });
            });

Any idea what could be wrong in my code?

Dietmar

alzubitariq commented 2 years ago

Hi AlanFloyd,

If you are using MediaPicker, i think the workaround is to put some delay between picking a picture and the ImageCropper like this

var file = await MediaPicker.PickPhotoAsync(); await Task.Delay(2000); await ImageCropper.Current.Crop(new CropSettings() etc .....

I think the issue who is calling the OnActivityResult firstly with resultCode