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

Fix Image Scaling/Rotating #14501

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

alexknop
Copy link

@alexknop alexknop commented Feb 5, 2025

Problem:

Application is opening some images incorrectly. The image is being rotated incorrectly and the wrong heights/widths are being used for scaling.

For example, this image with a Width of 4096 pixels and Height of 3072 pixels and an orientation of upper-right was showing like this:
image
My screen size is 1080x2460

It appears after BitmapUtils.decodeSampledBitmapFromFile() is run, that the orientation is changed successfully.

The problem then was the height/width used. When originally using my screen size, the scaling was affected by stretching the image to fit the height of my screen. It needs to maintain the original aspect ratio of the image.

The image was then being rotated again, thus resulting in the image above.

Solution:
Take original heights and widths of file.
Determine if this image is to be rotated 90 or 270 degrees. If so, the height and width needs to accommodate for that.
Now, decode the bitmap using the original image's height/width.
Next, scale the image based on your screen size.

@alexknop alexknop force-pushed the fixScaling branch 2 times, most recently from 81b0169 to bb2846e Compare February 6, 2025 16:22
Signed-off-by: Alex Knop <[email protected]>
Copy link
Collaborator

@alperozturk96 alperozturk96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested various images with different sizes, including both landscape and portrait orientations. Throughout the testing process, I did not encounter any issues.

Thank you for the PR 💯

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

Successfully merging this pull request may close these issues.

3 participants