locked
MediaFile returns null on iOS RRS feed

  • Question

  • User187134 posted

    I am trying to fix 90 degrees rotation on iOS using the GetStreamWithImageRotatedForExternalStorage() method instead of GetStream().

    The issue I have is that GetStream() works but return the image rotated, but when using GetStreamWithImageRotatedForExternalStorage() it returns an empty stream?

    First I get the file using:

    file = await CrossMedia.Current.PickPhotoAsync()
    

    Then that file is passed to below method:

    public static byte[] GetCropedImage(MediaFile file)
    {
      using (var inputStream = new SKManagedStream(file.GetStreamWithImageRotatedForExternalStorage()))
      {
        using (var original = SKBitmap.Decode(inputStream))
        {
    Here original is null?
        }
      }
    }
    

    I use the latest version of MediaPlugin 4.0.1.1 and SkiaSharp 1.60.2.

    Both GetStream() and GetStreamWithImageRotatedForExternalStorage() works just fine on Android both with the image rotated correctly.

    Anyone having an idea what I am doing wrong or are we talking about a bug?

    Sunday, July 29, 2018 10:20 AM

Answers

  • User187134 posted

    Hi @ColeX thank you for the links. I already looked at those but didn't find a working solution. or at least not a "simple" one.

    What I ended up doing was using .GetStream() and then rotate the image in case of iOS like below:

    using (var original = SKBitmap.Decode(inputStream))
    {
      //iOS rotation bug fix
      if (Device.RuntimePlatform == Device.iOS)
      {
        using (var rotated = new SKBitmap(original.Height, original.Width))
        {
          using (var surface = new SKCanvas(rotated))
          {
            surface.Translate(rotated.Width, 0);
            surface.RotateDegrees(90);
            surface.DrawBitmap(original, 0, 0);
          }
          rotated.CopyTo(original);
        }
      }
      .....
    

    Also I am still using the default settings for

    file = await CrossMedia.Current.PickPhotoAsync()
    

    Thank you anyway!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, July 30, 2018 4:46 PM

All replies

  • User369978 posted

    This issue has been reported in github, here and here .

    Try the solution provided by others .

    https://stackoverflow.com/a/51203173/8187800

    https://github.com/jamesmontemagno/MediaPlugin/issues/485#issuecomment-397884726

    Monday, July 30, 2018 7:45 AM
  • User187134 posted

    Hi @ColeX thank you for the links. I already looked at those but didn't find a working solution. or at least not a "simple" one.

    What I ended up doing was using .GetStream() and then rotate the image in case of iOS like below:

    using (var original = SKBitmap.Decode(inputStream))
    {
      //iOS rotation bug fix
      if (Device.RuntimePlatform == Device.iOS)
      {
        using (var rotated = new SKBitmap(original.Height, original.Width))
        {
          using (var surface = new SKCanvas(rotated))
          {
            surface.Translate(rotated.Width, 0);
            surface.RotateDegrees(90);
            surface.DrawBitmap(original, 0, 0);
          }
          rotated.CopyTo(original);
        }
      }
      .....
    

    Also I am still using the default settings for

    file = await CrossMedia.Current.PickPhotoAsync()
    

    Thank you anyway!

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, July 30, 2018 4:46 PM