Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IImage does not take into account photo Orientation, causing IImage height and width to get mixed up #23391

Closed
jonmdev opened this issue Jul 2, 2024 · 4 comments
Labels
area-controls-image Image control platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue s/triaged Issue has been reviewed t/bug Something isn't working

Comments

@jonmdev
Copy link

jonmdev commented Jul 2, 2024

Description

When you take cell phone picture, the phone will typically store the orientation of the phone inside the metadata. This instructs systems whether it should be displayed tall or wide.

In Maui, if you take a photo by filepicker from the file system and set it to an image like:

var stream1 = await fileResult.OpenReadAsync();
var stream2 = await fileResult.OpenReadAsync();

imageSource = ImageSource.FromStream(() => stream1);
image.Source = imageSource;

iimage = PlatformImage.FromStream(stream2);
rawImageHeight = iimage.Height;
rawImageWidth = iimage.Width;
Debug.WriteLine("IIMAGE HEIGTH " + rawImageHeight);
Debug.WriteLine("IIMAGE WIDTH " + rawImageWidth);
Debug.WriteLine("IIMAGE H/WIDTH " + rawImageHeight/rawImageWidth);


image.SizeChanged += delegate {
        Debug.WriteLine("IMAGE WIDTH " + image.Width + " Height " + image.Height + " h/w " + image.Height/(double)image.Width );

};

Then if you compare, with a cell phone photo taken in portrait, you get the Image displaying this correctly, in UI scaled units:

Width: 300.1904761904762
Height: 400
h/w: 1.3324873096446699

This shows it is displaying it taller than wide as expected for a portrait photo.

However, IImage returns the wrong info:

IIMAGE HEIGHT: 3000
IIMAGE WIDTH: 4000
IIMAGE H/WIDTH: 0.75

IImage gets it inverted. It has not taken into account the "orientation" likely of the photo so now thinks it is wider than it is tall.

This makes using IImage impractical for resizing or judging expected file dimensions or anything really. It will work fine when thereis no orientation data (eg. a phone screencap) but a real photo causes inversion of height and width parameters.

Can IImage be fixed or is there any suggestion to make it work? How is Image taking into account the orientation data? Do we have any way to read the Orientation EXIF so we can correct for it ourselves with IImage?

Orientation is discussed here somewhat:
https://stackoverflow.com/questions/9371273/how-can-i-display-the-orientation-of-a-jpeg-file

I see it claimed that Image should be able to tell us the orientation but I don't know how as the info seems outdated:
https://www.cyotek.com/blog/handling-the-orientation-exif-tag-in-images-using-csharp

Solution

Ideally IImage should automatically read the orientation in the same way as Image/ImageSource does so that these create identical outcomes.

Otherwise some method to read it manually and correct manually would work as well.

Any suggestions? Or is IImage just not useful and should be abandoned then?

Steps to Reproduce

  1. Take a photo with camera in portrait and landscape each.
  2. Try using FilePicker as discussed here https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/storage/file-picker?view=net-maui-8.0&tabs=android
  3. Assign stream to ImageSource and Image (normal result) and assign to IImage (mixes H/W)

Link to public reproduction project repository

I can post if it helps

Version with bug

8.0.61 SR6.1

Is this a regression from previous behavior?

No, this is something new

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

No response

Did you find any workaround?

No response

Relevant log output

No response

@jonmdev jonmdev added the t/bug Something isn't working label Jul 2, 2024
Copy link
Contributor

github-actions bot commented Jul 2, 2024

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@ninachen03
Copy link

Could you provide us with a sample project so we can investigate it further? Looking forward to your reply!

@QianaJiao QianaJiao added the s/triaged Issue has been reviewed label Sep 26, 2024
@jfversluis jfversluis added the s/needs-repro Attach a solution or code which reproduces the issue label Sep 26, 2024
Copy link
Contributor

Hi @jonmdev. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

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.

@dotnet-policy-service dotnet-policy-service bot added the s/no-recent-activity Issue has had no recent activity label Oct 1, 2024
Copy link
Contributor

This issue has been automatically marked as stale because it has been marked as requiring author feedback to reproduce the issue but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate.

@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2024
@dotnet-policy-service dotnet-policy-service bot removed the s/no-recent-activity Issue has had no recent activity label Nov 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-controls-image Image control platform/android 🤖 s/needs-repro Attach a solution or code which reproduces the issue s/triaged Issue has been reviewed t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants