Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Image Downsize does not treat image rotation as expected #450

Open
johannes-steurer opened this issue Jun 1, 2022 · 15 comments
Open

Image Downsize does not treat image rotation as expected #450

johannes-steurer opened this issue Jun 1, 2022 · 15 comments

Comments

@johannes-steurer
Copy link

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

@VincentBu
Copy link

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

@ghost
Copy link

ghost commented Jun 2, 2022

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.

@johannes-steurer
Copy link
Author

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,

@ghost ghost added the s/needs-attention label Jun 2, 2022
@VincentBu
Copy link

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

@janseris
Copy link

janseris commented Jun 2, 2022

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:
dotnet/maui#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" dotnet/maui#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 #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.

@VincentBu
Copy link

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

@johannes-steurer
Copy link
Author

I cannot run my App on Windows unfotunately

@Christerad
Copy link

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
Copy link

@johannes-steurer any work around ?

@janseris
Copy link

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.

@Christerad
Copy link

Christerad commented Mar 14, 2023

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

@MartinMilan
Copy link

Any updates? I still have this problem when downsizing

@mina5500
Copy link

Any updates ... we need a fix @jfversluis

@mina5500
Copy link

please assist we need a fix ... @davidortinau

@johannes-steurer
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants