[ImageResizer] Fix the missing settings of png encoder (#46695)

- Apply codec-specific encoder properties (e.g. JPEG quality) in the
transcode path when transforms are required, matching WPF behavior.
- Apply PngInterlaceOption to the WinRT PNG encoder via the
"InterlaceOption" BitmapPropertySet entry; previously the setting was
persisted but never passed to the encoder.

<!-- Enter a brief description/summary of your PR here. What does it
fix/what does it change/how was it tested (even manually, if necessary)?
-->
## Summary of the Pull Request

<!-- Please review the items on the PR checklist before submitting-->
## PR Checklist

- [ ] Closes: #xxx
<!-- - [ ] Closes: #yyy (add separate lines for additional resolved
issues) -->
- [ ] **Communication:** I've discussed this with core contributors
already. If the work hasn't been agreed, this work might be rejected
- [ ] **Tests:** Added/updated and all pass
- [ ] **Localization:** All end-user-facing strings can be localized
- [ ] **Dev docs:** Added/updated
- [ ] **New binaries:** Added on the required places
- [ ] [JSON for
signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json)
for new binaries
- [ ] [WXS for
installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs)
for new binaries and localization folder
- [ ] [YML for CI
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml)
for new test projects
- [ ] [YML for signed
pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml)
- [ ] **Documentation updated:** If checked, please file a pull request
on [our docs
repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys)
and link it here: #xxx

<!-- Provide a more detailed description of the PR, other things fixed,
or any additional comments/features here -->
## Detailed Description of the Pull Request / Additional comments

<!-- Describe how you validated the behavior. Add automated tests
wherever possible, but list manual validation steps taken as well -->
## Validation Steps Performed

Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
moooyo
2026-04-01 18:25:53 +08:00
committed by GitHub
parent 42924e71c7
commit 4ce451edd0

View File

@@ -121,6 +121,14 @@ namespace ImageResizer.Models
{ {
encoder.BitmapTransform.Bounds = cropBounds.Value; encoder.BitmapTransform.Bounds = cropBounds.Value;
} }
// Apply codec-specific properties (e.g., JPEG quality).
// Must be set after transforms since re-encoding will occur.
var encoderProps = GetEncoderPropertySet(encoderGuid);
if (encoderProps != null)
{
await encoder.BitmapProperties.SetPropertiesAsync(encoderProps);
}
} }
} }
else else
@@ -515,6 +523,25 @@ namespace ImageResizer.Models
}; };
} }
if (encoderGuid == BitmapEncoder.PngEncoderId)
{
// Only override when explicitly set; Default lets the WIC encoder decide.
if (_settings.PngInterlaceOption == PngInterlaceOption.On)
{
return new BitmapPropertySet
{
{ "InterlaceOption", new BitmapTypedValue(true, PropertyType.Boolean) },
};
}
else if (_settings.PngInterlaceOption == PngInterlaceOption.Off)
{
return new BitmapPropertySet
{
{ "InterlaceOption", new BitmapTypedValue(false, PropertyType.Boolean) },
};
}
}
if (encoderGuid == BitmapEncoder.TiffEncoderId) if (encoderGuid == BitmapEncoder.TiffEncoderId)
{ {
var compressionMethod = MapTiffCompression(_settings.TiffCompressOption); var compressionMethod = MapTiffCompression(_settings.TiffCompressOption);