Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

4.4.5-beta iOS 13.2 Image result rotated 90 or 180 degree #760

Closed
Jacko1394 opened this issue Oct 18, 2019 · 67 comments
Closed

4.4.5-beta iOS 13.2 Image result rotated 90 or 180 degree #760

Jacko1394 opened this issue Oct 18, 2019 · 67 comments

Comments

@Jacko1394
Copy link

Hi James,

Thanks for pushing out 4.4.3-5 betas quickly!
iOS 13.2 doesn't crash when tapping 'Use Photo' anymore 👍 but if I take a portrait image, the result ends up rotated 90.

Taking a landscape image works one way, but the other way will rotate 180 upside-down.

Apple making things difficult... (iPhone 8)

@Jacko1394
Copy link
Author

Still seems to be having rotation issues with 4.4.6-beta

@Jacko1394
Copy link
Author

So with SaveToAlbum=true, the photo is saved in the correct orientation, but in my Forms app the ImageSource displays wrong for portrait images... 🤔

@jamesmontemagno
Copy link
Owner

Are you using "PickPhoto" or "PickPhotos"?

@Jacko1394
Copy link
Author

'PickPhoto' and 'PickPhotos' are both working, the rotation issue happens when using 'TakePhoto', the photo result after tapping 'Use Photo' gets rotated.

@Kiitoksia
Copy link

We had the same issue, but the version of iOS did not matter (this is happening on 12.4.X), so I'm not entirely sure this is the same problem.
Once I set AllowCropping=false, then the results came through in the correct rotation.

@MitchBomcanhao
Copy link

MitchBomcanhao commented Oct 24, 2019

using media plugin 4.0.1.5, with the same app build (build with xcode 10), also having issues.
We take/pick an image and generate a thumbnail based on the properties of the original image.

  • iOS 13.2 has that image rotated 90 degrees to the left. (iPhone XS Max)
  • iOS 13.1.2 has no issues (iPhone X)
  • iOS 12.4 has no issues (iPhone 5s)

@OPunktSchmidt
Copy link

OPunktSchmidt commented Oct 28, 2019

I can confirm this problem too. The image saved to the album is rotated correctly but the ImageStream is rotated wrong. Only on iOs, Android works.

This problem occurs with TakePhotoAsync AND PickPhotoAsync.

@hponaganti
Copy link

Looks only beta updates are being done. Is beta safe to use in Production Environment. When will be a release to the nuget ?

@clintonrocksmith
Copy link

I think it's due to the EXIF data being stripped out from the photo(s) as they're parsed back to the main application. The EXIF data holds information about how to rotate the photo.

@ronnyhash
Copy link

My users started to complain about this issue, so I tested it myself. I'm experiencing this exact issue after updating to iOS 13.2. Any possibility of a fix for this soon? My production app is suffering.

@ronnyhash
Copy link

@jamesmontemagno Hey James, we really appreciate this plugin, but right now it cannot be used at all for iOS 13.2. This image rotation issue is Critical. It isn't possible to take an image with the correct rotation, and it is affecting all users. Can we please get an update on this?

I tried setting AllowCropping to false, but that didn't help. I tried setting SaveToAlbum to true, but that didn't work either.

We really need a fix for this fast! This has been a know issue for a couple weeks now. Please help!

@VictorK1902
Copy link

Some of our users also experience this issue after upgrading to 13.2. I'm currently using 4.3.1-beta.

@brettchangus
Copy link

Same problem here on iOS 13.2.2 + 4.0.1.5. Worked fine on iOS 13.1.2.

@dhewitson
Copy link

Similar problem here with iOS 13.2 and plugin version 4.0.1.5
EXIF Data is missing on images saved using the plugin.

@klogeaage
Copy link
Contributor

klogeaage commented Nov 10, 2019

Yes, we also see this problem on iOS 13.2 and 13.2.2 with 4.4.6-beta. No EXIF data no matter whether you pick photo or take a new. This is very serious :-(.

@jveltd
Copy link

jveltd commented Nov 11, 2019

We're also seeing this issue which is isolated to iOS 13.2.x

Tested on many iOS devices and after updating from 13.1.x to 13.2.x the images are now rotated.

Is there an ETA on a fix for this please?

@jveltd
Copy link

jveltd commented Nov 11, 2019

As a work around, if you set the following:

SaveMetaData = false

Then this will not rotate the image e.g.

var photo = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
{
  Name = "temp.jpg",
  PhotoSize = Plugin.Media.Abstractions.PhotoSize.MaxWidthHeight,
  MaxWidthHeight = 600,
  DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Rear,
  CompressionQuality = 92,
  AllowCropping = true,
  SaveMetaData = false,
  SaveToAlbum = false
});

@klogeaage
Copy link
Contributor

klogeaage commented Nov 11, 2019

Yes, but unfortunately the ability to read the metadata (EXIF) from the picked file is a significant feature in our use of the plugin.
But thanks for the information.
James, the problem can be reproduced with any simulator running 13.2.x and picking the last of the 6 standard images from the camera roll, i.e. the one from San Francisco with the pretty flowers. Maybe this makes it easier for you to solve the problem?

@mnidhk
Copy link

mnidhk commented Nov 11, 2019

I can confirm this problem too.
iOS 13.2 fixed some other issues for me but breaks this one.
Is it a bug in iOS13.2 or in this plugin!?
"SaveMetaData = false" works for me as a workaround for now

@vksuman
Copy link

vksuman commented Nov 12, 2019

This problem is with iOS13 and 4.0.1.5 and any phone. We have experienced this issue with iPhone 5S, 6, 6S and 7. We can't use SaveMetaData = false as metadata (EXIF) from the picked file is a significant feature for our app.

Could we have fix for this bug ASAP please???

@jamesmontemagno
Copy link
Owner

jamesmontemagno commented Nov 12, 2019

Thanks @klogeaage for the repro of the built in image. I do see that being rotated weirdly.

It looks like the exif data is coming in just fine on the file, so if you using a library that reads the exif data it will be there.

Else, it looks like you may need to use: GetStreamWithImageRotatedForExternalStorage

image

When I use this it is just fine. I can also confirm that this works fine on iOS 12.2 as well.

@jamesmontemagno
Copy link
Owner

So, this looks like it is a bug with iOS 13.2, when calling:

return UIImage.FromImage(cgi, 1.0f, orientation);

This function is called when you resize the image. If you mark the image as: PhotoSize = PhotoSize.Full you will not see the rotation at all when using the normal GetStream

So, if you are resizing the image you should request the rotated image back to display. If you are not then you can use the normal stream.

A question I have though is if anyone is experiencing this in applications compiled against Xcode 10 and iOS 12 or is everyone compiling against Xcode 11 and iOS 13?

@jamesmontemagno
Copy link
Owner

After talking with the team and looking at the bindings, I really think that this is an iOS 13.2 bug and not a bug in the library itself. I have walked through a few work arounds for everyone here to validate in your own app.

@jveltd
Copy link

jveltd commented Nov 12, 2019

Thanks for the update James. I guess we can all feed this back to Apple for them to investigate.

@dhewitson
Copy link

Thanks James, the workarounds are enough for us.
Just an FYI we're compiling against XCode 11 and iOS 13

@jamesmontemagno
Copy link
Owner

Alright, mind blown here.....

Apple decided to randomly remove an API from iOS 13:

if(UIDevice.CurrentDevice.CheckSystemVersion(13, 0))
                {
                    transform = new CILanczosScaleTransform
                    {
                        Scale = scale,
                        InputImage = sourceImage,
                        AspectRatio = 1.0f
                    };
                }
                else
                {
                    transform = new CILanczosScaleTransform
                    {
                        Scale = scale,
                        Image = sourceImage,
                        AspectRatio = 1.0f
                    };
                }

Using the new InputImage seems to rotate correct! pushing out a new package :)

@jamesmontemagno
Copy link
Owner

Or I hope that is it. Still validating.

@dhewitson
Copy link

Classic Apple...

@jamesmontemagno
Copy link
Owner

Looks like that wasn't it.

So a few workarounds that I have validated:

  1. Save MetaData = false
  2. Call GetStreamWithImageRotatedForExternalStorage, which will rotate it based on exif data (SaveMetaData must be true).

My only other assumption is that the UIImageView maybe changed how it renders items out.... not sure though.

@klogeaage
Copy link
Contributor

@jamesmontemagno:

It looks like the exif data is coming in just fine on the file, so if you using a library that reads the exif data it will be there.

Nope, that is part of the problem that no EXIF data is available with the file. I use the ImageMetadataReader.ReadMetadata(filePath) method from theMetadataExtractor2.2 package, and it cannot find location data or when the picture was digitized, both of which work fine pre iOS 13.2.

So I'm sorry, but I don't think those of us that depend on EXIF data have a workaround.

@jamesmontemagno
Copy link
Owner

Can confirm that 13.3 doesn't not fix it. I think it has to do with metadata somewhat. A bit confusing that if you say save metadata to false that it works.

@dinisvieira-xo
Copy link

@jamesmontemagno It's also working for me if I set "SaveMetaData=false;" for both PickPhotoAsync and TakePhotoAsync.

Versions:
iOS version: 13.2.x
Media Plugin: 4.0.1.5
Xamarin Forms: 2.5.x

@mr5z
Copy link

mr5z commented Nov 21, 2019

Hi,

Not a solution but to just add some info.
It may helped if everyone who have issues with the image orientation also includes in which software, platform/OS they viewed the image.

Images in iOS are not actually rotated after it has been taken from camera, it just saves the exif orientation metadata for the client consumption. It was claimed that when the image is viewed on the default image app in Windows, it doesn't honor the exif metadata and just draws the image thus producing incorrect results sometimes.

I have also reproduced the bug when I used this exif reader tool to view the image. The image I took displays incorrectly on that site but displays correctly when viewed directly using Chrome for Mac.

@kdekok
Copy link

kdekok commented Nov 21, 2019

I can confim having these issues, and i'm glad this thread proves i'm not the only one!

We don't call GetStream(), but just upload the raw file after
var file = await CrossMedia.Current.TakePhotoAsync(options);

When needed, we rotate it on the backend, depending on the EXIF data, which is missing for our users since iOS 13.2. I hope Apple will fix this soon, otherwise we'll have to give the workarounds a go but that would require an app update unfortuantely...

@MatthewKapteyn
Copy link

MatthewKapteyn commented Nov 21, 2019

I think the $100 bounty should go to #747 (comment)

Used their code instead of the wacky manual copy-pasteover code in SaveImageWithMetadata and all is right in the world again.

internal static bool SaveImageWithMetadata(UIImage image, float quality, NSDictionary meta, string path, string pathExtension)
{
    try
    {
        pathExtension = pathExtension.ToLowerInvariant();
        var finalQuality = quality;
        var imageData = pathExtension == "jpg" ? image.AsJPEG(finalQuality) : image.AsPNG();

        //continue to move down quality , rare instances
        while (imageData == null && finalQuality > 0)
        {
            finalQuality -= 0.05f;
            imageData = image.AsJPEG(finalQuality);
        }

        if (imageData == null)
            throw new NullReferenceException("Unable to convert image to jpeg, please ensure file exists or lower quality level");

        var saveSuccessful = false;

        // Copy over meta data
        using (var ciImage = CIImage.FromData(imageData))
        {
            using (var newImageSource = ciImage.CreateBySettingProperties(meta))
            {
                using (var ciContext = new CIContext())
                {
                    if (pathExtension == "jpg")
                        saveSuccessful = ciContext.WriteJpegRepresentation(newImageSource, NSUrl.FromFilename(path), CGColorSpace.CreateSrgb(), new NSDictionary(), out var error);
                    else
                        saveSuccessful = ciContext.WritePngRepresentation(newImageSource, NSUrl.FromFilename(path), CIFormat.ARGB8, CGColorSpace.CreateSrgb(), new NSDictionary(), out var error);
                }
            }
        }

        return saveSuccessful;
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Unable to save image with metadata: {ex}");
    }

    return false;
}

@MatthewKapteyn
Copy link

one word of caution is that I have no use for PNG in my app and have no idea if the settings in WritePngRepresentation are ideal.

jamesmontemagno added a commit that referenced this issue Nov 21, 2019
@MatthewKapteyn
Copy link

One last note while i'm running builds on a variety of devices. No issues with backwards compatibility going as far back as iOS 9.3.4.

@jamesmontemagno
Copy link
Owner

Cools, I am putting in code that only applies this to iOS 13+ as that was the main impact. Thanks for testing it out and I will figure out the bounty stuff when tested out.

@ManbirSinghRakhra
Copy link
Contributor

@MatthewKapteyn Thanks very much for appreciating it. We need it very badly. I spent a long time to create a patch in my code. I am glad that you guys liked it.

I will update my project for Media Plugin

@jamesmontemagno
Copy link
Owner

can try latest 4.4.7-beta

@klogeaage
Copy link
Contributor

klogeaage commented Nov 22, 2019

Good work :-).
I think the new code in SaveImageWithMetadataiOS13() should be standard as it is simpler and more flexible. But lets first see if it introduces other problems in the coming months.

@ClausElmann
Copy link

ClausElmann commented Nov 22, 2019

Hi James

EDIT - On Mac, updating nuget works, so I am god for now :-)

The beta introduces further dependencies, can I overcome this?

Severity Code Description Project File Line Suppression State
Error Failed to add reference. The package 'Xam.Plugin.Media' tried to add a framework reference to 'System.Drawing.Common.dll' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.
Error HRESULT E_FAIL has been returned from a call to a COM component.

Severity Code Description Project File Line Suppression State
Error NU1605 Detected package downgrade: Plugin.Permissions from 5.0.0-beta to 3.0.0.12. Reference the package directly from the project to select a different version.
Mobile.Portable -> Xam.Plugin.Media 4.4.7-beta -> Plugin.Permissions (>= 5.0.0-beta)
Mobile.Portable -> Plugin.Permissions (>= 3.0.0.12)

@jamesmontemagno
Copy link
Owner

So, you should use 5.0.0-beta of permisions plugin else you will run into issues.

Make sure any other library you are using from me is using this version. so like geolocator or other stuff.

For System.Drawing.Common... oddd it shouldn't be there. Make sure you are using package refereneces: see: MvvmCross/MvvmCross#3531

@jamesmontemagno
Copy link
Owner

I'll push out 4.4.8, let me know if that helps.

@ClausElmann
Copy link

Still some strange issue on nuget WS2019/Windows.

Severity Code Description Project File Line Suppression State
Error Failed to add reference. The package 'Xam.Plugin.Geolocator' tried to add a framework reference to 'System.Drawing.Common.dll' which was not found in the GAC. This is possibly a bug in the package. Please contact the package owners for assistance.
Error HRESULT E_FAIL has been returned from a call to a COM component.

On Mac - it works perfekt.

@RhomGit
Copy link

RhomGit commented Nov 23, 2019

Possibly related to: xamarin/xamarin-macios#7249

@rshah1803
Copy link

thanks @jamesmontemagno it fixed rotation and exif issue but still one minor issue.

In my app I am using TakephotoSync to click photo and then displaying it on page after photo is clicked, for displaying photos I have written code in OnAppearing() of the page, but after TakePhotoSync its not calling OnAppeatring(), is this something can you please check

Thanks,
Rohan

@jamesmontemagno
Copy link
Owner

@ClausElmann you will need to convert to PackageReferences in your app. It is super simple to do.

@vbmanuel2295
Copy link

vbmanuel2295 commented Dec 11, 2019

Hi @jamesmontemagno ,

After updating to 4.4.8, issue still exist on iOS 13.2.3 using PickPhotoAsync and SaveMetadata = false.

Can you or someone please let me know what's your options to make it work on iOS?

Below is my code for reference.

image

Thank you in advance

@rshah1803
Copy link

@jamesmontemagno when can we get stable version with rotation and exif data fix please

Thanks
Rohan

@fjavaler
Copy link

fjavaler commented Dec 20, 2019

I am having this issue after upgrading to iPadOS 13.3.

@ralphcode
Copy link

ralphcode commented Dec 22, 2019

Thanks. Comment is now obsolete.

@Alextorres950325
Copy link

Alextorres950325 commented Sep 18, 2020

Again happens on iOs 13.7

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests