jamesmontemagno/MediaPlugin: Selected picture is rotating when comes to UI in IOS app

SreeeeSreeee INMember ✭✭✭✭✭
edited November 2018 in Xamarin.Forms

@JamesMontemagno I follow this blog for taking photos from gallery and camera. But the selected picture is showing right rotated form when comes to UI in IOS. Problem is only when using the camera and no issues with the gallery. This feature is working fine in android and UWP.

Screenshot added below:

Code of Camera:

async void CameraClick()
        {
            try
            {
                await CrossMedia.Current.Initialize();
                if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
                {
                    await DisplayAlert("Camera", "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;
                profileImage.Source = ImageSource.FromStream(() =>
                {
                    isPicture = true;
                    return _mediaFile.GetStream();
                });
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception:>" + ex);
            }
        }

Device : IOS SE

Version of the media plugin: 3.1.1

Control I am using to display the image : Xam.plugins.Forms.Imagecircle 2.0.2(For android and UWP I am using 1.8.1)

Gallery pictures are working fine and the issue is only when taking pictures using the camera. No issues in android and UWP part.
Please help me to solve this issue. Thanks in advance :)

Best Answer

Answers

  • SreeeeSreeee INMember ✭✭✭✭✭
    edited November 2018

    @ColeX My issue is only at the IOS part, no issues in android part.

    When I took a photo in ios camera the captured picture is rotating when added to UI. The screenshot in the question showing the original picture and the picture when comes to UI.

    Is your solution works for mine?

  • NMackayNMackay GBInsider, University mod

    @Sreeee said:
    @ColeX My issue is only at the IOS part, no issues in android part.

    When I took a photo in ios camera the captured picture is rotating when added to UI. The screenshot in the question showing the original picture and the picture when comes to UI.

    Is your solution works for mine?

    Cole's solution will fix your iOS issue. We had the same problem.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @ColeX said:
    Refer https://github.com/jamesmontemagno/MediaPlugin/issues/495.

    Try to use GetStreamWithImageRotatedForExternalStorage instead of GetStream.

    When I apply this the android part image also rotating same like IOS.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @NMackay said:

    @Sreeee said:
    @ColeX My issue is only at the IOS part, no issues in android part.

    When I took a photo in ios camera the captured picture is rotating when added to UI. The screenshot in the question showing the original picture and the picture when comes to UI.

    Is your solution works for mine?

    Cole's solution will fix your iOS issue. We had the same problem.

    But it affecting the android part.

  • NMackayNMackay GBInsider, University mod

    @Sreeee said:

    @NMackay said:

    @Sreeee said:
    @ColeX My issue is only at the IOS part, no issues in android part.

    When I took a photo in ios camera the captured picture is rotating when added to UI. The screenshot in the question showing the original picture and the picture when comes to UI.

    Is your solution works for mine?

    Cole's solution will fix your iOS issue. We had the same problem.

    But it affecting the android part.

    Version 4.0.1.5 is working okay for us on Android, UWP and iOS. Suggest raising in issue on the github page.

  • SreeeeSreeee INMember ✭✭✭✭✭

    Thanks @NMackay and @ColeX for your comments, issue get solved :)

  • hyderabadihyderabadi USMember ✭✭✭

    Hello @Sreeee , I am also facing same issue. Please let me know the what are all the steps followed to resolve the issue.
    Please help me, Thanks.

  • SreeeeSreeee INMember ✭✭✭✭✭

    @hyderabadi Try to use GetStreamWithImageRotatedForExternalStorage instead of GetStream.

    public async void OpenMyCamera()
            {
                try
                {
                    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,
                        PhotoSize = PhotoSize.Medium
                    });
    
                    if (_mediaFile == null)
                        return;
    
                    picture.Source = ImageSource.FromStream(() =>
                    {
                        isPicture = true;
                        return _mediaFile.GetStreamWithImageRotatedForExternalStorage();
                    });
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception:>" + ex);
                }
            }
    
  • hyderabadihyderabadi USMember ✭✭✭

    @Sreeee Thanks for your reply.will give a try.

  • ledragonledragon Member ✭✭✭

    Seems that this happens for any images in the Gallery even if not taken with CrossMedia plugin: For anyone struggling with this the following helped me:

    https://www.syncfusion.com/kb/9632/how-to-resolve-image-rotated-when-loading-image-after-saving-image-in-ios-device

Sign In or Register to comment.