3

I'm very confused with how WPF is handling image rendering size under different DPI settings.

So my goal is to have PNG icons in my WPF app to display clearly under the default 100% Windows DPI settings (96 DPI) as well as for 125% (120 DPI), 150% (144 DPI), and 200% (192 DPI) to support the more and more popular hi-res 2K and 4K displays.

So this is what I have been testing:

  1. I have 4 variations of a 32 x 32 PNG image, they are set to 96, 120, 144, and 192 DPI respectively.
  2. I loaded all 4 with an Image control like this: <StackPanel> <Image Source="image_96_dpi.png" Stretch="None" /> <Image Source="image_120_dpi.png" Stretch="None" /> <Image Source="image_144_dpi.png" Stretch="None" /> <Image Source="image_192_dpi.png" Stretch="None" /> </StackPanel>
  3. The rendering result I got is as follow:
    • Render size for image_96_dpi.png: 32 x 32
    • Render size for image_120_dpi.png: 26 x 26
    • Render size for image_144_dpi.png: 32 x 32
    • Render size for image_192_dpi.png: 16 x 16

The result for 96, 120, and 192 dpi make sense, they all get scaled down properly but I don't get how the 144 dpi image also gets rendered as 32 x 32. The dpi is literally 150% to the default Windows dpi but it is rendered as a 96 dpi image.

Is this some sort of a bug?

Leon Zhou
  • 633
  • 6
  • 20

0 Answers0