medvedo
medvedo

Reputation: 563

Xamarin forms, photo taken with androidcamera device gives the image the wrong orientation

https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Camera

I use this project right here and as my title says when you take a photo on an androiddevice the image displays in landscape if you took it in portrait.

For iOS I have no trouble at all it is just on android i recieve this problem.

This is how the TakePicture task looks like in my CameraViewModel:

private async Task TakePicture ()
{
    Setup();

    ImageSource = null;

    await this._mediaPicker.TakePhotoAsync(new CameraMediaStorageOptions { DefaultCamera = CameraDevice.Front, MaxPixelDimension = 400}).ContinueWith(t =>
    {
        if (t.IsFaulted)
        {
            var s = t.Exception.InnerException.ToString();
        }
        else if (t.IsCanceled)
        {
            var canceled = true;
        }
        else
        {
            var mediaFile = t.Result;

            ImageSource = ImageSource.FromStream(() => mediaFile.Source);

            return mediaFile;
        }

        return null;
    }, _scheduler);
}

What I have tried to do after googling a bit is add this line of code inside the TakePicture function:

if (mediaFile.Exif.Orientation != ExifLib.ExifOrientation.TopLeft)
{
    System.Diagnostics.Debug.WriteLine ("picture is not portrait");
}

And once I take a photo on android "picture is not portrait" gets shown in the log but I am not quite sure where to go from here. If I add:

mediaFile.Exif.Orientation = ExifLib.ExifOrientation.TopLeft;

inside the if-statement the app crashes after you take a photo. No error-message or nothing. It just shuts down.

Upvotes: 0

Views: 428

Answers (1)

Prashant Cholachagudda
Prashant Cholachagudda

Reputation: 13092

You can find the code to adjust the orientation of an image captured from the Android camera here: https://forums.xamarin.com/discussion/comment/18786/#Comment_18786

Upvotes: 1

Related Questions