From 4ce451edd0a66ba4fe1366ff6a912c30be59feb3 Mon Sep 17 00:00:00 2001 From: moooyo <42196638+moooyo@users.noreply.github.com> Date: Wed, 1 Apr 2026 18:25:53 +0800 Subject: [PATCH] [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. ## Summary of the Pull Request ## PR Checklist - [ ] Closes: #xxx - [ ] **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 ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed Co-authored-by: Yu Leng (from Dev Box) Co-authored-by: Claude Sonnet 4.6 --- .../imageresizer/ui/Models/ResizeOperation.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/modules/imageresizer/ui/Models/ResizeOperation.cs b/src/modules/imageresizer/ui/Models/ResizeOperation.cs index 5c0af2b502..06a607e718 100644 --- a/src/modules/imageresizer/ui/Models/ResizeOperation.cs +++ b/src/modules/imageresizer/ui/Models/ResizeOperation.cs @@ -121,6 +121,14 @@ namespace ImageResizer.Models { 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 @@ -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) { var compressionMethod = MapTiffCompression(_settings.TiffCompressOption);