Microsoft.Maui.Graphics
Microsoft.Maui.Graphics copied to clipboard
Image Downsize does not treat image rotation as expected
Description
When downsizing an image as desciibed in https://docs.microsoft.com/en-us/dotnet/maui/user-interface/graphics/images the resulting downsized image behaves in the following way:
- downsizing an image taken in Landscape orientation => downsized image has the same orientation => OK
- rotate phone by 180° and take picture => downsized image is upside down (!)
- take picture in upright orientation => downsized image has landscape orientation (!)
Steps to Reproduce
Following code reproduces the issue on Andriod:
IImage image;
using (FileStream stream = new(source, FileMode.Open)) {
image = PlatformImage.FromStream(stream);
}
if (image != null) {
IImage newImage = image.Downsize(800);
using FileStream stream = new(destination, FileMode.Create);
await newImage.SaveAsync(stream);
}
Version with bug
6.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android, I was not able test on other platforms
Affected platform versions
Andriod 12 - API 31
Did you find any workaround?
No response
Relevant log output
No response
would you like to share a sample project to facilitate our work?
Hi @johannes-steurer. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I am not really able to share my current project publicly, unfortunately.
The issue is fairly simple to reproduce.
optional: Take a picture via
Picture = MediaPicker.CapturePhotoAsync()
and resize it using it's path
Picture.FileName
using the code mentioned above
Hope this helps.
Thanks,
I write a project and run it on android emulator, looks like image has the same orientation with machine MauiApp7654.zip
180°

90°

0°

You are actually lucky that Downsize sort of works on Android. Resize does not and on Windows, nothing works.
This issue affects jpg images and the cause is:
https://github.com/dotnet/maui/issues/13902
I don't see any change coming.
The repo has been inactive for 2 months.
I have received info that it "is not dead" https://github.com/dotnet/maui/issues/6998 but nothing had changed ever since.
There is a workaround which I am using (doesn't work for Windows because image processing is not fully implemented there https://github.com/dotnet/Microsoft.Maui.Graphics/issues/422). The workaround is to read before processing and then save after processing appropriate EXIF info/metadata if the image is jpg. I am using ExifLibrary NuGet package because all other possibilities could not write or did not fully work (including the Xamarin Android API).
That however should be implemented in MAUI itself because it is a basic feature for basically any scenario, e. g. like yours - resizing a portrait photo. Which is clearly a mainstream scenario in any app which works with camera or uploads photos.
For advanced image processing, the EXIF info should be managed by the library as well because some of these properties change with the processing and cannot be just simply copied from the original image.
Have you run into the error described in dotnet/maui#7616 when running app on Windows?
I cannot run my App on Windows unfotunately
I found the same problem with .net maui graphics just like @johannes-steurer said any work around ? i need to use image downsize feature
@johannes-steurer any work around ?
There is an expensive both for processing time and programming time workaround - use Exif Library to extract exif info out before resize and then put it in the resized image. This will end up with preserving the rotation property as well as GPS info but will incorrectly preserve old resolution info etc.
well at least the work around worked for me, need to manually rotate the image though XD. At least that 1 problem solved
Any updates? I still have this problem when downsizing
Any updates ... we need a fix @jfversluis
please assist we need a fix ... @davidortinau
Also waiting urgently for a fix. It's 1.5 years now since reporting!