Camera picture is left rotated when comes to UI in IOS

SreeeeSreeee INMember ✭✭✭✭✭

The picture taken from the IOS camera is left rotated when showing it in the UI.

I already faced this type of issue and solved by this thread. But in this case, I am saving only the image path to List.

Camera code:

public async void OpenMyCamera()
        {
            try
            {
                List<string> images = new List<string>();
                await CrossMedia.Current.Initialize();

                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("Alert", "No camera available.", "Ok");
                    return;
                }

                _mediaFile = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
                {
                    Directory = "Sample",
                    Name = "test.jpg",
                    AllowCropping = true
                });

                if (_mediaFile == null)
                    return;

                //Saving only the path to list.
                images.Add(_mediaFile.Path);

                MessagingCenter.Send<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", images);

            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception:>" + ex);
            }
        }

I am using FlowListView for showing the pictures using the following code.

MessagingCenter.Subscribe<App, List<string>>((App)Xamarin.Forms.Application.Current, "ImagesSelected", (s, images) =>
                {
                    for (int i = 0; i < images.Count; i++)
                    {
                        _images.Add(images[i]);
                        _images = new ObservableCollection<string>(_images.Distinct());
                        listItems.FlowItemsSource = _images;
                    }
                });
            }

What is the solution for this issue?

Best Answer

  • LandLuLandLu Xamurai
    Accepted Answer

    It seems this is a known issue when you set AllowCropping to true, check the image's exif data you will find the edited image has been rotated by 90 degrees. If you haven't used the image's metadata, try to close it to fix that:

    var _mediaFile = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        Directory = "Sample",
        Name = "test.jpg",
        AllowCropping = true,
        SaveMetaData = false
    });
    

Answers

  • SreeeeSreeee INMember ✭✭✭✭✭

    Hi @Quintán and @ColeX Any solution for this issue?

  • SreeeeSreeee INMember ✭✭✭✭✭

    @LandLu, @Charwaka and @NMackay Please suggest a solution.

  • LandLuLandLu Member, Xamarin Team Xamurai
    Accepted Answer

    It seems this is a known issue when you set AllowCropping to true, check the image's exif data you will find the edited image has been rotated by 90 degrees. If you haven't used the image's metadata, try to close it to fix that:

    var _mediaFile = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        Directory = "Sample",
        Name = "test.jpg",
        AllowCropping = true,
        SaveMetaData = false
    });
    
  • SreeeeSreeee INMember ✭✭✭✭✭

    @LandLu said:
    It seems this is a known issue when you set AllowCropping to true, check the image's exif data you will find the edited image has been rotated by 90 degrees. If you haven't used the image's metadata, try to close it to fix that:

    var _mediaFile = await Plugin.Media.CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
    {
        Directory = "Sample",
        Name = "test.jpg",
        AllowCropping = true,
        SaveMetaData = false
    });
    

    I will try this and update you.

  • SreeeeSreeee INMember ✭✭✭✭✭

    You are awesome @LandLu. Can you please update the same answer here.

  • LandLuLandLu Member, Xamarin Team Xamurai

    Glad it helped you and feel free to ask questions here.
    I will also inform my colleagues to update you on the SO.

Sign In or Register to comment.