Skip to content

fix(drawing): keep the aspect ratio when a decode size is requested - #1669

Merged
ChrisPulman merged 3 commits into
mainfrom
fix/wpf-bitmap-decode-size
Aug 2, 2026
Merged

fix(drawing): keep the aspect ratio when a decode size is requested#1669
ChrisPulman merged 3 commits into
mainfrom
fix/wpf-bitmap-decode-size

Conversation

@glennawatson

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Bug fix, plus removal of dead code.

What is the new behavior?

  • Requesting a decode size keeps the source proportions: the loader reads the image header without decoding pixels, then sets only the dimension that constrains the result so the other is derived.
  • The unreferenced duplicate platform folder is gone, and the decode-size behaviour is now covered by tests, including an end-to-end decode.

What is the current behavior?

  • The loader set both decode dimensions whenever the caller supplied both, and the imaging layer stretches to fit when both are set, so a requested size whose ratio differed from the source silently distorted the image.
  • A platform folder duplicating the desktop one was referenced by no item group, so it reached no target framework at all.

What might this PR break?

  • Load and LoadFromResource no 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

  • I have read the Contribute guide
  • Tests have been added or updated (for bug fixes / features)
  • Docs have been added or updated (for bug fixes / features)
  • Changes target the main branch
  • PR title follows Conventional Commits

Additional 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).

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

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (b1d3f14) to head (23b3a51).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- 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.
@sonarqubecloud

sonarqubecloud Bot commented Aug 2, 2026

Copy link
Copy Markdown

@ChrisPulman
ChrisPulman merged commit f110782 into main Aug 2, 2026
13 checks passed
@ChrisPulman
ChrisPulman deleted the fix/wpf-bitmap-decode-size branch August 2, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants