简体   繁体   English

Xamarin形式,使用androidcamera设备拍摄的照片使图像方向错误

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

https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Camera 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. 我在这里使用这个项目,正如我的标题所说,当您在androiddevice上拍照时,如果您是纵向拍摄,则图像会以横向显示。

For iOS I have no trouble at all it is just on android i recieve this problem. 对于iOS我完全没有问题,只是在android上我就收到了这个问题。

This is how the TakePicture task looks like in my CameraViewModel: 这就是TakePicture任务在我的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: 谷歌搜索后我想做的是在TakePicture函数中添加以下代码:

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. 而且,一旦我在android上拍了张照片,“图片不是肖像”就会显示在日志中,但我不太确定从这里到哪里。 If I add: 如果我添加:

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

inside the if-statement the app crashes after you take a photo. 在if语句中拍照后,应用程序崩溃。 No error-message or nothing. 没有错误消息或什么都没有。 It just shuts down. 它只是关闭。

您可以在此处找到用于调整从Android摄像头捕获的图像的方向的代码: https : //forums.xamarin.com/discussion/comment/18786/#Comment_18786

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM