Microsoft.Maui.Graphics icon indicating copy to clipboard operation
Microsoft.Maui.Graphics copied to clipboard

Image Downsize does not treat image rotation as expected

Open johannes-steurer opened this issue 3 years ago • 15 comments
trafficstars

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

johannes-steurer avatar Jun 01 '22 06:06 johannes-steurer

would you like to share a sample project to facilitate our work?

VincentBu avatar Jun 02 '22 02:06 VincentBu

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.

ghost avatar Jun 02 '22 02:06 ghost

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,

johannes-steurer avatar Jun 02 '22 05:06 johannes-steurer

I write a project and run it on android emulator, looks like image has the same orientation with machine MauiApp7654.zip

180° image

90° image

image

VincentBu avatar Jun 02 '22 09:06 VincentBu

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.

janseris avatar Jun 02 '22 11:06 janseris

Have you run into the error described in dotnet/maui#7616 when running app on Windows?

VincentBu avatar Jun 07 '22 08:06 VincentBu

I cannot run my App on Windows unfotunately

johannes-steurer avatar Jun 08 '22 07:06 johannes-steurer

I found the same problem with .net maui graphics just like @johannes-steurer said any work around ? i need to use image downsize feature

Christerad avatar Mar 13 '23 09:03 Christerad

@johannes-steurer any work around ?

Christerad avatar Mar 14 '23 04:03 Christerad

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.

janseris avatar Mar 14 '23 06:03 janseris

well at least the work around worked for me, need to manually rotate the image though XD. At least that 1 problem solved

Christerad avatar Mar 14 '23 09:03 Christerad

Any updates? I still have this problem when downsizing

MartinMilan avatar Sep 11 '23 10:09 MartinMilan

Any updates ... we need a fix @jfversluis

mina5500 avatar Nov 27 '23 13:11 mina5500

please assist we need a fix ... @davidortinau

mina5500 avatar Nov 30 '23 06:11 mina5500

Also waiting urgently for a fix. It's 1.5 years now since reporting!

johannes-steurer avatar Nov 30 '23 14:11 johannes-steurer