Xamarin形式:jamesmontemagno/MediaPlugin:在IOS应用程序中添加到UI时,所选图片正在旋转 [英] Xamarin forms: jamesmontemagno/MediaPlugin: Selected picture is rotating when added to UI in IOS app
问题描述
我跟随此博客从画廊和相机中拍照.但是当涉及到IOS中的UI时,所选图片以向右旋转的形式显示. 仅在使用相机时出现问题,画廊没有问题.此功能在android和UWP中正常工作.
I followed this blog for taking photos from the gallery and camera. But the selected picture is showing in right rotated form when it comes to the UI in IOS. Problem only occurs when using the camera and I have no issues with the gallery. This feature is working fine in android and UWP.
下面添加了屏幕截图:
相机代码:
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);
}
}
设备:iOS SE
媒体插件的版本:3.1.1
我用来显示图像的控件:Xam.plugins.Forms.Imagecircle 2.0.2(对于Android和UWP,我正在使用1.8.1)
图库图片运行良好,问题仅在于使用相机拍摄时. android和UWP部分没有问题.
Gallery pictures are working fine and the issue is only when taking pictures using the camera. No issues in android and UWP part.
推荐答案
原因:
即使在Xamarin
之外,这也是一种常见的体验.这是由iOS
引起的.
This is a common experience even outside of Xamarin
. It is caused by iOS
.
UIImage具有属性
imageOrientation
,该属性指示 UIImageView和其他UIImage使用者可以旋转原始图像数据. 此标志很有可能被保存到exif数据中 在上载的jpeg图片中,但是您用于查看该图片的程序不是 纪念那面旗帜.
A UIImage has a property
imageOrientation
, which instructs the UIImageView and other UIImage consumers to rotate the raw image data. There's a good chance that this flag is being saved to the exif data in the uploaded jpeg image, but the program you use to view it is not honoring that flag.
解决方案:
在Github的jamesmontemagno/MediaPlugin
的Issues
部分中,有几个问题,例如您遇到的问题.似乎使用GetStreamWithImageRotatedForExternalStorage
可以解决此问题.
In the Issues
part in jamesmontemagno/MediaPlugin
in Github, there are several issues like the problem you meet. Seems using GetStreamWithImageRotatedForExternalStorage
will fix this issue.
您可以参考: https://github.com/jamesmontemagno/MediaPlugin/issues/333
以另一种方式,您可以自己旋转图像.
In another way, you can rotate the image yourself.
以下一些链接可能会对您有所帮助:
Here are some links that might help you:
iOS UIImagePickerController上传后的结果图像方向
这篇关于Xamarin形式:jamesmontemagno/MediaPlugin:在IOS应用程序中添加到UI时,所选图片正在旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!