fix(drawing): keep the aspect ratio when a decode size is requested - #1669
Merged
Conversation
The imaging layer preserves proportions only when exactly one decode dimension is set, and stretches to fit when both are. The loader set both whenever the caller supplied both, so asking for a size whose ratio differed from the source silently distorted the image. - Read the source dimensions from the image header, without decoding pixels, and set only the dimension that constrains the result so the other is derived. A source that cannot be measured falls back to the requested width rather than stretching. - Cover the choice of dimension, and add an end-to-end decode that fails if a request is applied in a way that distorts.
Every file under the folder targeted the Windows presentation stack and duplicated the folder that already compiles into the desktop targets. No item group referenced it, so it reached no target framework, and the types it declared could not serve any other one either. Its size and point converters still described themselves as Android conversions, which is where they were copied from.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1669 +/- ##
==========================================
+ Coverage 97.60% 97.98% +0.37%
==========================================
Files 127 127
Lines 6757 6785 +28
Branches 1025 1027 +2
==========================================
+ Hits 6595 6648 +53
+ Misses 91 64 -27
- Partials 71 73 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Set the cache option before the resource identifier, so the image is read up front rather than on demand. Without it the loader held the caller's file open for as long as the bitmap lived. - Measure a resource through a stream the loader owns and closes, rather than handing the identifier to a decoder that keeps it open. A resource that is not a file is left unmeasured, and the decode is then constrained by width alone, which still preserves the proportions. - Cover the measuring, dimension-choosing and resource paths, including a request the source cannot fill, a header the codec cannot read and a resource that cannot be opened.
|
ChrisPulman
approved these changes
Aug 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What kind of change does this PR introduce?
Bug fix, plus removal of dead code.
What is the new behavior?
What is the current behavior?
What might this PR break?
LoadandLoadFromResourceno longer return exactly the requested width and height when the two disagree with the source ratio; they now return the largest undistorted image that fits. Callers relying on the previous stretch-to-fit result will see different dimensions.Checklist
mainbranchAdditional information
The new end-to-end test was confirmed to fail against the previous loader on Windows, reporting an aspect ratio of exactly 1 against the source's 1.0667. Verified on Windows across all seven desktop target frameworks (11,011 tests) and on Linux (6,228 tests).