简体   繁体   中英

Why does WPF resize images with no metadata DPI setting when Stretch=“None”?

WPF is enlarging my images, and I'm trying to figure out why. From this answer , I know that WPF will automatically resize images whose metadata DPI settings differ from the monitor DPI setting. However, I've confirmed that my images have no metadata DPI settings. Why, then, is WPF resizing my images?

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfApplication1"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Image Source="Untitled-1.png" Stretch="None" />
    </Grid>
</Window>

I can't find this documented anywhere, but after some experimentation it seems clear that when an image lacks DPI metadata, WPF assumes the image was composed for 96 DPI. Therefore, a good summary of WPF's behavior is:

WPF will automatically scale images by the ratio of Monitor DPI / Image DPI. It will read the image metadata to determine the Image DPI, and if the metadata specifies no DPI, WPF will use 96 as the image DPI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM