I have an application that the user can add photos through the gallery using the FilePicker.PickMultipleAsync. And also user can take a picture this functionality is using CrossMedia plugin.
If the user takes a photo (CrossMedia) in portrait format, the photo is converted into ImageSource to be displayed. If the user selects the images, it does the same conversion process to ImageSource, but in this case the photos are automatically rotated to the right.
This happens with photos that were taken by the camera's native app. If the user downloads any image and selects it from the gallery, the problem does not happen. The problem started after switching the plugin to FilePicker.
What can I do to display the original image?
Versions: Xamarin.Forms: 5.0.0.2401 Xamarin.Essentials: 1.7.3
Code of the plugin
var result = await FilePicker.PickMultipleAsync(new PickOptions
{
PickerTitle = "Choose Images",
FileTypes = FilePickerFileType.Images
});
if (result != null)
{
foreach (var item in result)
{
AttachedFiles.Add(new AttachmentFiles(item));
}
}
public AttachmentFiles(FileResult imgSource)
{
var imageAsBytes = ImageHelper.ConvertStreamToByteArray(Task.Run(async () => await imgSource.OpenReadAsync()).Result);
var resizer = DependencyService.Get<IImageResize>();
this.ImageId = Guid.NewGuid();
this.Source = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));
this.SourceT = ImageSource.FromStream(() => new MemoryStream(resizer.ResizeImage(imageAsBytes, 70, 70)));
}
The image on the left I downloaded from the internet and it appears correctly. The image on the right I took by the camera and chose from the gallery